QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#474185 | #801. 回文自动机 | templatetemplate# | 0 | 2ms | 11936kb | C++17 | 1.5kb | 2024-07-12 16:33:27 | 2024-07-12 16:33:27 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &x){
x=0;
bool flag=0;
char ch=getchar();
while(ch<'0'||ch>'9') flag=flag||(ch=='-'),ch=getchar();
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
x=flag?-x:x;
}
template<typename T,typename ...Args>inline void read(T &x,Args &...args){
read(x),read(args...);
}
template<typename T>inline void prt(T x){
if(x>9) prt(x/10);
putchar(x%10+'0');
}
template<typename T>inline void put(T x){
if(x<0) putchar('-'),x=-x;
prt(x);
}
template<typename T>inline void put(char ch,T x){
put(x),putchar(ch);
}
template<typename T,typename ...Args>inline void put(char ch,T x,Args ...args){
put(ch,x),put(ch,args...);
}
#define N 1000005
char s[N];
int n;
struct Trie{
int trie[N][26],fail[N],idx,lst,len[N],num[N];
Trie(){fail[1]=fail[0]=idx=1,len[1]=-1,lst=0;}
inline int getfail(int x,int i){
while(i-len[x]-1<0||s[i-len[x]-1]!=s[i]) x=fail[x];
return x;
}
inline void extend(int c,int i){
int x=getfail(lst,i);
if(!trie[x][c]){
len[++idx]=len[x]+2;
fail[idx]=trie[getfail(x,i)][c];
trie[x][c]=idx;
}
lst=trie[x][c],num[lst]++;
}
inline void prework(){
for(int i=idx;i>1;i--) num[fail[i]]+=num[i];
}
}P;
int main(){
scanf("%s",s+1),n=strlen(s+1);
for(int i=1;i<=n;i++) P.extend(s[i]-'a',i);
P.prework();
long long ans=0;
for(int i=2;i<=P.idx;i++) ans=max(ans,1ll*P.num[i]*P.len[i]*P.len[i]);
put('\n',ans);
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 11936kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
3978
result:
wrong answer expected '5594', found '3978'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%