QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#607301#5119. Perfect Wordice_cupWA 19ms10128kbC++141.1kb2024-10-03 14:37:452024-10-03 14:37:47

Judging History

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

  • [2024-10-03 14:37:47]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:10128kb
  • [2024-10-03 14:37:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define MID int mid=(l+r)>>1;
#define ls p<<1
#define rs p<<1|1
unordered_map<ll,bool>mp;
string a[100100];
vector<ll>hs[100100];
vector<int>s[30];
int n,b=29,st[100100];
ll po[100100];
bool ck(int i){
	int m=a[i].size();
	if(m>500){
		if(!st[i])return 0;
		int fl=0;
		for(int tmp:s[a[i][0]-'a']){
			if(tmp<=m)fl++;
		}
		return fl==m;
	}
	for(int l=0;l<m;l++){
		for(int r=l+1;r<m;r++){
			ll tmp=hs[i][r];
			if(l)tmp-=hs[i][l-1]*po[r-l+1];
			if(!mp[tmp])return 0;
		}
	}
	return 1;
}
int main(){
	po[0]=1;
	for(int i=1;i<=1000;i++)po[i]=po[i-1]*b;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		int m=a[i].size();
		hs[i].resize(m);
		int fl=1;
		for(int j=0;j<m;j++){
			if(j)fl&=(a[i][j]==a[i][j-1]);
			if(!j)hs[i][j]=a[i][j]-'a';
			else hs[i][j]=hs[i][j-1]*b+a[i][j]-'a';
		}
		mp[hs[i][m-1]]=1;
		if(fl){
			st[i]=1;
			s[a[i][0]-'a'].push_back(m);
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(ck(i)){
			int m=a[i].size();
			ans=max(ans,m);
		}
	}
	cout<<ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 10128kb

input:

4
a
t
b
ab

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 19ms
memory: 9532kb

input:

310
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaaaaaa
aaaaaaaa
aaaaaaaaa
aaaaaaaaaa
aaaaaaaaaaa
aaaaaaaaaaaa
aaaaaaaaaaaaa
aaaaaaaaaaaaaa
aaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaa...

output:

300

result:

ok 1 number(s): "300"

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 9720kb

input:

4347
bbaaaab
aabab
bbaaaaababaaaba
aababaaaabbbabababaaaba
ababbabbbbbabbbabbab
bbbbbbb
bbbabbbabbabaab
aabbbbabbbbaa
aabaaabbbbbabaaababaa
aaabababba
aaababbaabab
abbababbabbab
bababaabbbbaaa
aaaaaabaaaababaa
ababaababba
babaababbbababaaab
bb
abbbaaaababa
b
ab
aaabbbbb
abaabaaaaababbbab
bbaaabaab
b...

output:

17

result:

wrong answer 1st numbers differ - expected: '10', found: '17'