QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#473524#801. 回文自动机MEKHANE#0 0ms0kbC++14853b2024-07-12 08:26:242024-07-12 08:26:24

Judging History

你现在查看的是最新测评结果

  • [2024-07-12 08:26:24]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [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;
}

Details

Tip: Click on the bar to expand more detailed information

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%