QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#253657 | #801. 回文自动机 | Mobius_127 | 0 | 11ms | 63932kb | C++14 | 2.8kb | 2023-11-17 11:09:14 | 2023-11-17 11:09:14 |
Judging History
answer
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <cctype>
#include <vector>
#include <queue>
#include <bitset>
#define mem(arr, x) memset(arr, x, sizeof(arr))
#define mcy(arr, b) memcpy(arr, b, sizeof(arr))
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
typedef long long ll;
typedef pair <int, int> Pii;
const int INF=0x3f3f3f3f;
const int cp=998244353;
inline int mod(int x){return x+(x<0?cp:0)-(x>=cp?cp:0);}
inline void plust(int &x, int y){x=mod(x+y);return ;}
inline void minut(int &x, int y){x=mod(x-y);return ;}
inline int read(){
char ch=getchar();int x=0, f=1;
while(!isdigit(ch)){if(ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
return x*f;
}
inline void write(int x){
if(x<0) putchar('-'), x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
inline int ksm(int a, int b=cp-2){
int ret=1;
for(; b; b>>=1, a=1ll*a*a%cp)
if(b&1) ret=1ll*ret*a%cp;
return ret;
}
const int N=1e6+6;
namespace SAM{
const int M=N<<1;
int ch[M][26], fa[M], len[M], occ[M], lst, ndc;
inline int clr(int x){fa[x]=len[x]=occ[x]=0, mem(ch[x], 0);return x;}
inline void rmk(){clr(ndc=lst=1);}
inline int insert(char cc){
int p=lst, cur=clr(++ndc), c=cc-'a';len[cur]=len[p]+1;
for(; p&&!ch[p][c]; p=fa[p]) ch[p][c]=cur;int q=ch[p][c];
if(!q) fa[cur]=1;else if(len[q]==len[p]+1) fa[cur]=q;
else{
int nex=clr(++ndc);mcy(ch[nex], ch[q]);len[nex]=len[p]+1;fa[nex]=fa[q];
for(; p&&ch[p][c]==q; p=fa[p]) ch[p][c]=nex;fa[q]=fa[cur]=nex;
}return lst=cur;
}
int pos[N], f[M][25];vi G[M];
void dfs(int x){
for(int i=1; i<25; ++i) f[x][i]=f[f[x][i-1]][i-1];
for(auto v:G[x]) f[v][0]=x, dfs(v), occ[x]+=occ[v];
}
inline void ins(char *str, int m){
rmk();for(int i=1; i<=m; ++i) pos[i]=insert(str[i]), ++occ[pos[i]];
for(int i=2; i<=ndc; ++i) G[fa[i]].pb(i);dfs(1);
}
inline int find(int l, int r){
int u=pos[r];for(int i=24; i>=0; --i)
if(len[f[u][i]]>=r-l+1) u=f[u][i];
return u;
}
inline int OCC(int l, int r){return occ[find(l, r)];}
}
int n, p[N], L, R;char s[N], t[N<<1];ll ans;
inline void chk(int mid, int len){
int l=mid-len+1>>1, r=mid+len>>1;
// if(r-l+1>1)printf("find [%d %d]*%d\n", l, r, SAM :: OCC(l, r));
ll res=1LL*1LL*SAM :: OCC(l, r)*(r-l+1)*(r-l+1);
if(res>ans) ans=res, L=l, R=r;
}
signed main(){
scanf("%s", s+1);n=strlen(s+1);SAM :: ins(s, n);
t[0]='~', t[1]='#';for(int i=1; i<=n; ++i) t[i<<1]=s[i], t[i<<1|1]='#';
for(int i=1, mid=0, R=0; i<=n+n; ++i){
if(i<R) p[i]=min(R, p[mid+mid-i]);
while(t[i-p[i]-1]==t[i+p[i]+1]) ++p[i], chk(i, p[i]);
if(R<i+p[i]) mid=i, R=i+p[i];
}
for(int i=1; i<=(R-L+1>>1); ++i) if(s[L+i-1]!=s[R-i+1]) puts("!");
printf("%lld [%d %d]\n", ans, L, R);
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 11ms
memory: 63932kb
input:
bdgedcfadbabbfgeacdgbggaefddebabbfgeacdgbefaecfddffeddacbabfcgecedacbffeddacbabfebadggfafabcdfdeaabdeecgbcecegcgecedacbfgdagbgagafdegecadfebcdbgfacdecdegecadfebbcdfdeaabdbfgcbccfcaebcecfdfccagdafaeaacbggaefddebcbecdafageeaabcbdafadcbecdbcgcbdgedcfadbcaefbdfcbgfcdeceddaaffgcedfcdcgdcgbfdddfdadgagbbef...
output:
! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ...
result:
wrong output format ! is not a valid integer
Subtask #2:
score: 0
Skipped
Dependency #1:
0%