QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#480569 | #801. 回文自动机 | hy233# | 0 | 2ms | 10212kb | C++14 | 1.0kb | 2024-07-16 16:38:33 | 2024-07-16 16:38:33 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1000005;
const ll mod=1e9+7;
inline int rd()
{
int x=0; bool f=1;
char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())
if(ch=='-') f=0;
for(;ch>='0'&&ch<='9';ch=getchar())
x=x*10+(ch^48);
return f?x:-x;
}
char s[N];
int son[N][26],len[N],fail[N],cnt=1;
int num[N];
int getfail(int p,int i)
{
while(s[i-len[p]-1]!=s[i]) p=fail[p];
return p;
}
int main()
{
scanf("%s",s+1);
int n=strlen(s+1);
len[0]=-1;
fail[0]=1;
int p=0;
for(int i=1;i<=n;i++)
{
p=getfail(p,i);
if(!son[p][s[i]-'a'])
{
fail[cnt]=son[getfail(fail[p],i)][s[i]-'a'];
son[p][s[i]-'a']=++cnt;
len[cnt]=len[p]+2;
}
p=son[p][s[i]-'a'];
num[p]++;
}
vector<int> vec;
for(int i=0;i<=cnt;i++)
vec.push_back(i);
sort(vec.begin(),vec.end(),[&](int i,int j){ return len[i]>len[j]; });
for(auto x:vec)
num[fail[x]]+=num[x];
ll ans=0;
for(int i=2;i<=cnt;i++)
ans=max(ans,1ll*num[i]*len[i]*len[i]);
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 10212kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
9619
result:
wrong answer expected '5594', found '9619'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%