QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#91682 | #801. 回文自动机 | zyz07# | 0 | 24ms | 76656kb | C++11 | 2.1kb | 2023-03-29 12:49:38 | 2023-03-29 12:49:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define For(Ti,Ta,Tb) for(int Ti=(Ta);Ti<=(Tb);++Ti)
#define Dec(Ti,Ta,Tb) for(int Ti=(Ta);Ti>=(Tb);--Ti)
#define Debug(...) fprintf(stderr,__VA_ARGS__)
using ll=long long;
const int N=1e6+5,LogN=21;
int n;char s[N];
struct SAM{
struct Node{
int len,link,ed;
array<int,26> nxt;
}t[N*2];
int size,last,pres[N];
int New(){
t[size]={0,0,0,{}},t[size].nxt.fill(-1);
return size++;
}
void Init(){
size=last=0;
New(),t[0].link=-1;
}
void Extend(char _c){
int cur=New(),c=_c-'a';
t[cur].len=t[last].len+1,t[cur].ed=1;
int p=last;last=pres[t[cur].len]=cur;
while(~p&&!~t[p].nxt[c]) t[p].nxt[c]=cur,p=t[p].link;
if(!~p) return;
int q=t[p].nxt[c];
if(t[p].len+1==t[q].len) t[cur].link=q;
else{
int cl=size++;
t[cl]={t[p].len+1,t[q].link,0,t[q].nxt};
while(~p&&t[p].nxt[c]==q) t[p].nxt[c]=cl,p=t[p].link;
t[q].link=t[cur].link=cl;
}
}
vector<int> e[N*2];
int anc[N*2][LogN],siz[N*2];
void DFS(int u){
siz[u]=t[u].ed;
For(j,1,LogN-1) anc[u][j]=anc[anc[u][j-1]][j-1];
for(int v:e[u]) anc[v][0]=u,DFS(v),siz[u]+=siz[v];
}
void Build(){
For(i,1,size-1) e[t[i].link].push_back(i);
DFS(0);
}
int Substr(int l,int r){
int u=pres[r];
Dec(j,LogN-1,0){
int v=anc[u][j];
if(v&&t[v].len>=r-l+1) u=v;
}
return u;
}
}sam;
char t[N*2];int d[N*2],L[N*2],R[N*2],orig[N*2];
int main(){
ios::sync_with_stdio(false),cin.tie(nullptr);
cin>>(s+1),n=strlen(s+1);
sam.Init();
For(i,1,n) sam.Extend(s[i]);
sam.Build();
int len=0;
t[0]='@',t[++len]='#';
For(i,1,n) t[++len]=s[i],orig[len]=i,t[++len]='#';
For(i,1,len) R[i]=(orig[i]?orig[i]:R[i-1]);
Dec(i,len,1) L[i]=(orig[i]?orig[i]:L[i+1]);
ll ans=0;
for(int i=1,l=0,r=0;i<=len;++i){
if(r>=i) d[i]=min(r-i+1,d[l+r-i]);
else d[i]=1;
while(t[i-d[i]]==t[i+d[i]]){
int _l=L[i-d[i]],_r=R[i+d[i]];
if(_l<=_r&&orig[i-d[i]]&&orig[i+d[i]]){
ans=max(ans,1LL*sam.siz[sam.Substr(_l,_r)]*(_r-_l+1)*(_r-_l+1));
}
++d[i];
}
if(i+d[i]>r) l=i-d[i]+1,r=i+d[i]-1;
}
cout<<ans<<'\n';
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 24ms
memory: 76656kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
3384
result:
wrong answer expected '5594', found '3384'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%