QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#791876 | #801. 回文自动机 | 11d10xy | 0 | 0ms | 10204kb | C++14 | 910b | 2024-11-28 21:31:42 | 2024-11-28 21:31:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using i64=long long;
int n;
char str[1000010];
namespace am{
int ch[1000010][26],len[1000010],lnk[1000010],cnt[1000010],tot,lst;
vector<int>s;
void init(){
len[0]=-1,lnk[0]=0;
len[1]=0,lnk[1]=0;
tot=1,lst=1,s={-1};
}
void extend(int c){
s.push_back(c);
int u=lst;
for(;rbegin(s)[len[u]+1]!=c;u=lnk[u]);
int&v=ch[u][c];
if(!v){
v=++tot,len[v]=len[u]+2;
int p=lnk[u];
for(;p&&!ch[p][c];p=lnk[p]);
if(p)lnk[v]=ch[p][c];
else lnk[v]=1;
}lst=v,cnt[v]++;
}
i64 answer(){
i64 res=0;
for(int i=tot;i>=1;i--)cnt[lnk[i]]+=cnt[i];
for(int i=1;i<=tot;i++)res=max(res,cnt[i]*1ll*len[i]*len[i]);
return res;
}
}
int main(){
scanf("%s",str+1),n=strlen(str+1);
am::init();
for(int i=1;i<=n;i++)am::extend(str[i]-'a');
printf("%lld",am::answer());
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 10204kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
6576
result:
wrong answer expected '5594', found '6576'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%