QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#607249 | #5119. Perfect Word | ice_cup | WA | 3ms | 9708kb | C++14 | 873b | 2024-10-03 14:28:30 | 2024-10-03 14:28:35 |
Judging History
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'