QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#693988#8234. Period of a StringdoyoWA 0ms3552kbC++203.0kb2024-10-31 17:04:582024-10-31 17:05:04

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 17:05:04]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3552kb
  • [2024-10-31 17:04:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<=k;++i)
#define For(i,j,k) for(int i=j;i>=k;--i)
struct u{
	int alpha[26];
	int exi;
	int id;
}ept,mem[511111];
bool equal(u a,u b){
	FOR(i,0,25) if(a.alpha[i]!=b.alpha[i]) return false; 
	return true;
}
bool in_it(u a,u b){
	FOR(i,0,25) if(a.alpha[i]>b.alpha[i]) return false; 
	return true;
}
u del(u a,u b){
	FOR(i,0,25) b.alpha[i] -= a.alpha[i]; 
	return b;
}
void sol(){
	int n;
	cin>>n;
	vector<string> s(n+1);
	vector<int> l(n+1);
	int mxl = 0;
	FOR(i,1,n){
		cin>>s[i];
		l[i] = s[i].length();
		mxl = max(l[i],mxl);
	}
	vector<vector<int>> xz(2,vector<int>(mxl));
	vector<vector<int>> cnt(n+1,vector<int>(26));
	int memcnt = 0;
	For(i,n,1){
		int h = i&1;
		FOR(j,0,l[i]-1) mem[xz[h][j]] = ept;
		if(!xz[h][l[i]-1]) xz[h][l[i]-1] = ++memcnt;
		mem[xz[h][l[i]-1]].exi = 1;
		FOR(j,0,l[i]-1){
			if(!xz[h][l[i]-1]) xz[h][l[i]-1] = ++memcnt;
			++mem[xz[h][l[i]-1]].alpha[s[i][j]-'a'];
			++cnt[i][s[i][j]-'a'];
		}
		if(i!=n){
			FOR(j,0,l[i+1]-1){
				if(!xz[h^1][j]) continue;
				if(mem[xz[h^1][j]].exi){
					if(j<=l[i]-1){
						if(!xz[h][j]) xz[h][j] = ++memcnt;
						if(!mem[xz[h][j]].exi) mem[xz[h][j]] = mem[xz[h^1][j]];
						else{
							if(!equal(mem[xz[h][j]],mem[xz[h^1][j]])){
								cout<<"NO"<<'\n';
								return;
							}
						}
					}
					else{
						u lft={};
						FOR(k,0,25){
							lft.alpha[k] = mem[xz[h^1][j]].alpha[k] - j/l[i]*cnt[i][k];
							if(lft.alpha[k]<0){
								cout<<"NO"<<'\n';
								return;
							}
						}
						if(!xz[h][j%l[i]]) xz[h][j%l[i]] = ++memcnt;
						if(mem[xz[h][j%l[i]]].exi){
							if(!equal(mem[xz[h][j%l[i]]],lft)){
								cout<<"NO"<<'\n';
								return;
							}
						}
						else{
							mem[xz[h][j%l[i]]] = lft;
							mem[xz[h][j%l[i]]].exi = 1;
						}
					}
				}
			}
		}
//		FOR(k,0,l[i]-1){
//			cout<<"第"<<i<<"个字符串"<<k<<"级别限制:"<<endl;
//			cout<<"exi:"<<xz[i&1][k].exi<<endl;
//			FOR(j,0,25){
//				cout<<xz[i&1][k].alpha[j];
//			}
//			cout<<endl;
//		}
	}
	u now={};
	FOR(i,0,l[1]-1){
		if(!xz[1][i]) continue;
		if(mem[xz[1][i]].exi){
//			cout<<i<<"级别限制:"<<endl;
//			FOR(j,0,25){
//				cout<<xz[1][i].alpha[j];
//			}
//			cout<<endl;
			if(!in_it(now,mem[xz[1][i]])){
				cout<<"NO"<<'\n';
				return;
			}
			now = mem[xz[1][i]];
		}
	}
	cout<<"YES\n";
	now = ept;
	int ccnt = 0;
	FOR(i,0,l[1]-1){
		if(!xz[1][i]) continue;
		if(mem[xz[1][i]].exi){
			u ot = del(now,mem[xz[1][i]]);
			FOR(k,0,25){
				while(ot.alpha[k]){
					s[1][ccnt++] = 'a' + k;
					--ot.alpha[k];
				}
			}
			now = mem[xz[1][i]];
		}
	}
	FOR(i,2,n){
		FOR(j,0,l[i]-1){
			s[i][j] = s[i-1][j%l[i-1]];
		}
	}
	FOR(i,1,n){
		cout<<s[i]<<'\n';
	}
}
signed main(){
//	freopen("1.in","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--){
		sol();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3552kb

input:

4
2
abc
abcd
4
bbcaa
cabb
acabbbb
a
3
ab
aab
bbaaaaab
3
ab
aab
bbaaaaaa

output:

NO
NO
NO
NO

result:

wrong answer Jury has the answer but participant has not (test case 2)