HDU3068 POJ3974
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <string>
#include <cstring>
#define INT_MIN 0x80000000
#define INT_MAX 0xffffffff
#define N 1001000
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN(a,b) (a)<(b)?(a):(b)
#define LL long long
#define debug(x) cout<<#x<<":"<<(x)<<endl;
using namespace std;
char s[N<<1];
int p[N<<1];
int main()
{
//freopen("1.txt", "r", stdin);
//freopen("11.txt", "w", stdout);
//ios::sync_with_stdio(false);
while( ~scanf("%s", s) )
{
int len = strlen(s);
int id = 0 , max_len = 0;
for(int i=len; i>=0; i--)
{
s[i+i+2] = s[i];
s[i+i+1] = '#';
}
s[0] = '*';
for(int i=2; i<2*len+1; i++)
{
if(p[id]+id>i) p[i] = min(p[id-(i-id)], p[id]-(i-id));
else p[i] = 1;
while( s[i-p[i]] == s[i+p[i]] ) ++p[i];
if( id+p[id] < i+p[i] ) id = i;
if( max_len < p[i] ) max_len = p[i];
}
printf("%d\n", max_len-1);
}
return 0;
}