QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#64726 | #801. 回文自动机 | LinkZelda# | 0 | 3ms | 3516kb | C++14 | 1.0kb | 2022-11-25 14:09:26 | 2022-11-25 14:09:29 |
Judging History
answer
#include<bits/stdc++.h>
#define pr pair<int,int>
#define eps 1e-7
#define int long long
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int N=1000005;
char s[N];
int len[N],tr[26][N],fail[N],val[N],tot;
void init()
{
len[tot=1]=-1;
fail[1]=fail[0]=1;
}
int n,last;
int getfail(int cur,int x)
{
while(s[x-len[cur]-1]!=s[x])
cur=fail[cur];
return cur;
}
void ins(int x)
{
int cur=getfail(last,x);
if(!tr[s[x]-'a'][cur])
{
++tot;len[tot]=len[cur]+2;
fail[tot]=tr[s[x]-'a'][getfail(fail[cur],x)];
tr[s[x]-'a'][cur]=tot;
}
last=tr[s[x]-'a'][cur];
val[last]++;
}
int ans;
signed main()
{
scanf("%s",s+1);n=strlen(s+1);init();
for(int i=1;i<=n;i++)
ins(i);
for(int i=tot;i>=0;i--)
val[fail[i]]+=val[i];
for(int i=0;i<=tot;i++)
ans=max(ans,len[i]*len[i]*val[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: 3ms
memory: 3516kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
35000
result:
wrong answer expected '5594', found '35000'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%