关于NOIP T1
  • 板块学术版
  • 楼主Expert_Dream
  • 当前回复8
  • 已保存回复8
  • 发布时间2023/11/18 16:36
  • 上次更新2023/11/18 18:21:53
查看原帖
关于NOIP T1
768530
Expert_Dream楼主2023/11/18 16:36
#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
int n,m;
pair<string,int> s[N];
int tt[35];
string s2[N];
bool check(int x){
	if(s2[s[x].second] < s[1].first || (x==1 && s2[s[x].second] < s[2].first)) return true;
	else return false;
}
bool cmp(pair<string,int> x,pair<string,int> y){
	return x.first<y.first;
}
int vis[N];
char ch[N];
string ru[N];
int main(){
	freopen("dict.in","r",stdin);
	freopen("dict.out","w",stdout);	
	scanf("%d%d",&n,&m);
	for(int i =1;i <= n;i++) {
		scanf("%s",ch);
		ru[i]=ch;
	}if(n==1){
		cout<<1;
		exit(0);
	}
	for(int x = 1;x <= n;++x){
		memset(tt,0,sizeof tt);
		for(int i = 0 ;i < m;++i) tt[ru[x][i]-'a'] ++;
		string ans,ans2;
		for(int i=25;i >= 0;--i){
			int y=tt[i];
			while(tt[i]--) ans=ans+char(i+'a');
			tt[i]=y;
		}s[x].first = ans;
		for(int i=0;i <= 25;++i){
			while(tt[i]--) ans2=ans2+char(i+'a');
		}s2[x]=ans2;
	}
	for(int i = 1;i <= n;i++) s[i].second=i;
	sort(s+1,s+1+n,cmp);
	for(int i = 1;i <= n;i++){
		if(check(i))vis[s[i].second]=1;
	}for(int i = 1;i <= n;i++) printf("%d",vis[i]);
	return 0;
} 
/*

*/

时间复杂度 O(nm+nlog⁡n)O(nm+n\log n)。 考场大样例3s,能否AC?

2023/11/18 16:36
加载中...