QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#480338 | #801. 回文自动机 | 275307894a# | 0 | 0ms | 34644kb | C++14 | 1.8kb | 2024-07-16 14:10:19 | 2024-07-16 14:10:19 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned ll;using pii=pair<int,int>;
const int N=1e6+5,M=N*30+5,K=1000+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
#ifdef LOCAL
#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
#else
#define gdb(...) void()
#endif
}using namespace Debug;
int n;char s[N];
namespace PAM{
int siz[N],son[N][26],len[N],cnt=1,La=1,link[N];
int jump(int x,int id){while(x^1&&s[id-len[x]-1]^s[id]) x=link[x];return x;}
ll ans=0;
vector<int> S[N];
void dfs(int x,int La){
for(int i:S[x]) dfs(i,x),siz[x]+=siz[i];
if(x^1) ans=max(ans,1ll*siz[x]*len[x]*len[x]);
}
void build(){
len[0]=0;len[1]=-1;link[0]=1;
for(int i=1;i<=n;i++){
int p=jump(La,i);
if(!son[p][s[i]-'a']){
len[++cnt]=len[p]+2;
son[p][s[i]-'a']=cnt;
link[cnt]=jump(link[p],i);
}
p=son[p][s[i]-'a'];siz[p]++;La=p;
}
for(int i=0;i<=cnt;i++) if(i^1) S[link[i]].push_back(i);
dfs(1,0);
printf("%lld\n",ans);
}
}
void Solve(){
scanf("%s",s+1);n=strlen(s+1);
PAM::build();
}
int main(){
int t=1;
// scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 34644kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
4772
result:
wrong answer expected '5594', found '4772'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%