WA了第二个点qwq,调了好久了
代码:
#include<bits/stdc++.h>
#define N 1000010
using namespace std;
int n,f[N],ans;
char s[N];
void manacher(int x){
int mid=0,maxn=0;
for(int i=1;i<=x;i+=2){
f[i]=(maxn>i)?min(f[2*mid-i],maxn-i):1;
if(maxn>i&&i-f[i]<mid){
ans=max(ans,2*(i-mid));
}
while(s[i+f[i]]==s[i-f[i]]){
f[i]++;
}
if(f[i]+i>maxn){
mid=i,maxn=f[i]+i;
}
}
}
int read(){
int x=0;
char ch=getchar();
while(ch<'0'||ch>'9'){
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<3)+(x<<1)+ch-'0';
ch=getchar();
}
return x;
}
int main(){
n=read();
scanf("%s",s+1);
s[1]='$';
for(int i=n;i;i--){
s[i*2+1]='$',s[i*2]=s[i];
}
manacher(2*n);
printf("%d",ans);
return 0;
}