#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
using namespace std;
int p[400000];
char s[400000],a[400000];
int main()
{
int n,m;
while(~scanf("%s",s))
{
a[0] = '@' ;n = 1;
int len = strlen(s);
for(int i=0;i<len;i++)
{
a[n++] = '#';
a[n++] =s[i];
}
a[n++] = '#';
a[n] = '\0';
m = strlen(a);
// cout<<a<<endl;
int minx = 0,id,mmax = 0;
for(int i=1;i<m;i++)
{
if(minx>i)
p[i] = min(p[2*id-i],minx-i);
else
p[i] = 1;
while(a[i+p[i]]==a[i-p[i]])p[i]++;
if(p[i]+i>minx)
{
minx = p[i]+i;
id = i;
}
mmax = max(p[i],mmax);
}
printf("%d\n",mmax-1);
}
}
hdu 最大回文 Manacher算法
最新推荐文章于 2020-03-30 17:32:28 发布