mannacher算发的处理要将字符串的各个字母之间加上'#' a[0]='$' a[2*len+1]='#' a[2*len+2]='#'
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<vector>
#include<map>
using namespace std;
//typedef long long lld;
const int oo=0x3f3f3f3f;
//const lld OO=1LL<<61;
const int MOD=(1e9)+7;
const int maxn=110005;
char str[maxn],a[maxn<<2];
int p[maxn<<1];
void init_string(int len)
{
a[0]='$';
for(int i=1;i<=len;i++)
{
a[2*i-1]='#';
a[2*i]=str[i];
}
a[2*len+1]='#';
a[2*len+2]='#';
}
int Manacher(int len)
{
int mx = 0, id = 0;
for (int i = 1; i <= len; i++)
{
if (mx > i)
p[i] = min(mx - i, p[2 * id - i]);
else
p[i] = 1;
while (a[i - p[i]] == a[i + p[i]])
p[i]++;
if (p[i] + i > mx)
{
mx = p[i] + i;
id = i;
}
}
int ans=0;
for(int i=1;i<=len;i++)
{
ans=max(ans,p[i]-1);
}
return ans;
}
int main()
{
while(scanf("%s",str+1)!=EOF)
{
int n=strlen(str+1);
init_string(n);
cout<<Manacher(2*n+1)<<endl;
}
return 0;
}
/**
abcd
-> abcdabc
abcda
*/