QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#607249#5119. Perfect Wordice_cupWA 3ms9708kbC++14873b2024-10-03 14:28:302024-10-03 14:28:35

Judging History

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

  • [2024-10-03 14:28:35]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:9708kb
  • [2024-10-03 14:28:30]
  • 提交

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];
int n,b=29;
ll po[100100];
bool ck(int i){
	int m=a[i].size();
	if(1ll*m*m>3*n)return 0;
	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);
		for(int j=0;j<m;j++){
			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;
	}
	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: 2ms
memory: 9708kb

input:

4
a
t
b
ab

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 9472kb

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:

30

result:

wrong answer 1st numbers differ - expected: '300', found: '30'