QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#341510#801. 回文自动机jucason_xu#0 2ms9796kbC++141.6kb2024-02-29 19:32:252024-02-29 19:32:26

Judging History

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

  • [2024-02-29 19:32:26]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:9796kb
  • [2024-02-29 19:32:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rd(i,n) for(int i=0;i<n;i++)
#define rp(i,n) for(int i=1;i<=n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=b;i>=a;i--)
#define st string
#define vt vector
#define pb push_back
//#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n,len[1000005],cnt=2,fail[1000005];
int nxt[1000005][26],sz[1000005],fa[1000005];
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin>>s;
    int cur=2;
    len[1]=-1,len[2]=0;
    fail[2]=1;
    for(int i=0;i<s.size();i++){
        while(cur!=1&&(i-len[cur]-1<0||s[i]!=s[i-len[cur]-1])){
 //       	cout<<cur<<endl;
        	cur=fail[cur];
		}
        if(!nxt[cur][s[i]-'a']){
            nxt[cur][s[i]-'a']=++cnt;
            fa[cnt]=cur;
            len[cnt]=len[cur]+2;
            if(cur==1)fail[cnt]=2;
            else{
                int x=fail[cur];
                while(x!=1&&(i-len[x]-1<0||s[i]!=s[i-len[x]-1])){
  //              	cout<<x<<endl;
                	x=fail[x];
				}
				if(!nxt[x][s[i]-'a'])fail[cnt]=2;
                else fail[cnt]=nxt[x][s[i]-'a'];
            }
  //          cout<<cnt<<" "<<fail[cnt]<<endl;
        }
        cur=nxt[cur][s[i]-'a'];
        sz[cur]++;
    }
    ll ans=0;
    per(i,3,cnt){
 //   	cout<<len[i]<<" "<<sz[i]<<endl;
        ans=max(ans,1ll*len[i]*len[i]*sz[i]);
        sz[fa[i]]+=sz[i];
        sz[fail[i]]+=sz[i];
    }
    cout<<ans<<endl;
    return 0;
}
//Rain Rain Rain

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: 9796kb

input:

bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...

output:

6521

result:

wrong answer expected '5594', found '6521'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%