80RE求调
查看原帖
80RE求调
702659
l0k9j8h7楼主2024/6/19 19:03

#include<bits/stdc++.h>
using namespace std;
#define M 3001
char w[M][M],w2[M][M],wmin[M][M],wmax[M][M],minnus;
deque<short> q;
inline int fread(){
	int x;bool f=0;char c;
	c=getchar();
	if(c=='-')f=-1;
	else x=c-'0';
	c=getchar();
	while(c!=' '&&c!='\n'){
		x*=10;
		x+=c-'0';
		c=getchar();
	}
	return x;
}
/*inline string* sread(){
  string a;
  char c;
  while(1){
  c=getchar();
  if(c=='\n')return &a;
  a+=c;
  }
  }*/
int m,n;
int main()
{
	
	m=fread(),n=fread();
	if(m==1){
		cout<<1;
		return 0;
	}
	for(int i=1;i<=m;i++){
		char e;
		for(int j=1;j<=n;j++){
			
			cin>>e;
			w[i][j]=e-'a'+1;
			w2[i][j]=w[i][j];
		}
		getchar();
	}
	for(int i=1;i<=m;i++){
		sort(w2[i]+1,w2[i]+n+1);
		
	}
	//accepted
	for(int i=1;i<=m;i++){
		for (int j = 1; j <=n; j++)
		{
			/* code */wmin[i][j]=w2[i][j],wmax[i][j]=w2[i][n-j+1];
		}
		
	}
	
	deque<int> q;
	for(int i=1;i<=m;i++)q.push_back(i);
	for(int i=1;i<=n;i++){
		
		char maxchar='z'-'a'+1;
		queue<int> t;
		int x;
		do{
			x=q.front();
			
			q.pop_front();if(q.empty())minnus=x;
			if(wmax[x][i]<maxchar){
				
				while(!q.empty()&&x>q.back())q.pop_back();
				maxchar=wmax[x][i];
				q.push_back(x);
			}
			else if(wmax[x][i]==maxchar)q.push_back(x);
			
		}while(!q.empty()&&x<q.front());
		
	}
	if(minnus==0)minnus=q.front();
	for(int i=1;i<=m;i++){
		int j=1;
		while(wmin[i][j]==wmax[minnus][j]){
			j++;
		}
		if(wmin[i][j]>=wmax[minnus][j]){
			if(i==minnus)putchar('1');
			else putchar('0');
		}
		else putchar('1');
		
		
		
	}
	return 0;
}

RE ON #9#10

2024/6/19 19:03
加载中...