QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#341521 | #801. 回文自动机 | jucason_xu# | 0 | 0ms | 9844kb | C++14 | 1.5kb | 2024-02-29 19:35:07 | 2024-02-29 19:35:08 |
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])){
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])){
x=fail[x];
}
if(!nxt[x][s[i]-'a'])fail[cnt]=2;
else fail[cnt]=nxt[x][s[i]-'a'];
}
}
cur=nxt[cur][s[i]-'a'];
sz[cur]++;
}
ll ans=0;
per(i,3,cnt){
sz[fail[i]]+=sz[i];
}
per(i,3,cnt){
ans=max(ans,1ll*len[i]*len[i]*sz[i]);
sz[fa[i]]+=sz[i];
}
cout<<ans<<endl;
return 0;
}
//Rain Rain Rain
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 9844kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
6286
result:
wrong answer expected '5594', found '6286'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%