QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#476819 | #801. 回文自动机 | Doqe# | 0 | 2ms | 9940kb | C++14 | 926b | 2024-07-13 21:04:51 | 2024-07-13 21:04:52 |
answer
#include<bits/stdc++.h>
using namespace std;
namespace PAM
{
const int N=1e6+10;
char s[N];int n;
int fa[N],tr[N][26],len[N],tt,up;
int cnt[N];
void ini()
{
tt=1;fa[1]=0,len[0]=-1;up=0;
}
int nxt(int x,int n)
{
while(s[n]!=s[n-len[x]-1])x=fa[x];
return x;
}
void ins(int c)
{
int u=up;s[++n]=c;
u=nxt(u,n);
if(!tr[u][c-'a'])
{
tr[u][c-'a']=++tt;
len[tt]=len[u]+2;
fa[tt]=nxt(fa[u],n);
}
up=tr[u][c-'a'];
++cnt[up];
}
}
char s[PAM::N];
int main()
{
PAM::ini();int c;
cin>>s+1;
for(int i=1;s[i];++i)PAM::ins(s[i]);
long long ans=0;
for(int i=PAM::tt;i;--i)
{
PAM::cnt[PAM::fa[i]]+=PAM::cnt[i];
ans=max(ans,1ll*PAM::len[i]*PAM::len[i]*PAM::cnt[i]);
}
cout<<ans<<endl;
}
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: 9940kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
4772
result:
wrong answer expected '5594', found '4772'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%