QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#473524 | #801. 回文自动机 | MEKHANE# | 0 | 0ms | 0kb | C++14 | 853b | 2024-07-12 08:26:24 | 2024-07-12 08:26:24 |
answer
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
const int N=1e6+5;
int n,las,tot,ch[2*N][26],siz[2*N],f[2*N],l[2*N];
long long ans;
char s[N];
vector<int> v[2*N];
int find1(int x,int id){return (x==0?0:((id-l[x]-1>=1&&s[id]==s[id-l[x]-1])?x:find1(f[x],id)));}
void ins(int id,int c){
int dq=find1(las,id),dq1;
if(ch[dq][c]) dq1=ch[dq][c];
else{
ch[dq][c]=dq1=++tot,l[dq1]=l[dq]+2;
int d1=find1(f[dq],id); f[dq1]=ch[d1][c];
}siz[dq1]++,las=dq1;
}
void dfs(int x){
for(auto dq:v[x]) dfs(dq),siz[x]+=siz[dq];
if(x) ans=max(ans,1ll*siz[x]*l[x]*l[x]);
}
signed main(){
ios::sync_with_stdio(false);
cin>>(s+1),n=strlen(s+1),las=0,tot=1,f[1]=0,l[0]=-1;
rep(i,1,n) ins(i,s[i]-'c');
rep(i,1,tot) v[f[i]].push_back(i);
dfs(0),cout<<ans;
}
詳細信息
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 0
Time Limit Exceeded
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%