QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#474605 | #801. 回文自动机 | positive1 | 0 | 1ms | 5752kb | C++14 | 813b | 2024-07-12 20:53:19 | 2024-07-12 20:53:20 |
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn=1000010;
struct node
{
int fa,len,cnt,son[26];
}m[maxn];
char s[maxn];
int main()
{
ios::sync_with_stdio(false),cin.tie(0);
int i,p=0,tot=1;
long long ans=0;
cin>>s;
m[1].fa=0;
m[1].len=0;
m[0].len=-1;
for(i=0;s[i];i++)
{
if(m[p].len==i) p=m[p].fa;
for(;s[i]!=s[i-m[p].len-1];p=m[p].fa);
int ch=s[i]-'a';
if(m[p].son[ch]) p=m[p].son[ch];
else
{
int q=++tot;
m[p].son[ch]=q;
m[q].len=m[p].len+2;
if(p)
{
for(p=m[p].fa;!m[p].son[ch];p=m[p].fa);
m[q].fa=m[p].son[ch];
}
else m[q].fa=1;
p=q;
}
m[p].cnt++;
}
for(i=tot;i>1;i--)
{
m[m[i].fa].cnt+=m[i].cnt;
ans=max(ans,1LL*m[i].len*m[i].len*m[i].cnt);
}
cout<<ans<<'\n';
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: 1ms
memory: 5752kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
6132
result:
wrong answer expected '5594', found '6132'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%