先贴一下代码~
//by 减维
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<algorithm>
#define ll long long
#define maxn
using namespace std; char s[],a[];
int nxt[],mr,pos,ans; int main()
{
char ch=getchar();
a[]='#';a[]='#';
gets(s+);int ls=strlen(s+);
for(int i=;i<=ls;++i)a[i*]=s[i],a[i*+]='#';int n=ls*+;
for(int i=;i<=n;++i){
if(mr>i)nxt[i]=min(nxt[*pos-i],mr-i);
else nxt[i]=;
while(a[i-nxt[i]]==a[i+nxt[i]])nxt[i]++;
if(i+nxt[i]>mr)mr=i+nxt[i],pos=i;
ans=max(ans,nxt[i]-);
}
printf("%d",ans);
}