aaaa abab
4 3
ACode:
#pragma warning(disable:4786)//使命名长度不受限制 #pragma comment(linker, "/STACK:102400000,102400000")//手工开栈 #include <map> #include <set> #include <queue> #include <cmath> #include <stack> #include <cctype> #include <cstdio> #include <cstring> #include <stdlib.h> #include <iostream> #include <algorithm> #define rd(x) scanf("%d",&x) #define rd2(x,y) scanf("%d%d",&x,&y) #define rds(x) scanf("%s",x) #define rdc(x) scanf("%c",&x) #define ll long long int #define maxn 110011 #define mod 1000000007 #define INF 0x3f3f3f3f //int 最大值 #define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i) #define MT(x,i) memset(x,i,sizeof(x)) #define PI acos(-1.0) #define E exp(1) using namespace std; char str[maxn]; char ma[maxn<<1]; int mp[maxn<<1]; int ans; void Manacher(){ int l=0;ma[l++]='$'; ma[l++]='#';ans=-INF; int m=strlen(str); FOR(i,0,m-1){ ma[l++]=str[i]; ma[l++]='#'; } ma[l]=0; int mx=0,id=0; FOR(i,0,l-1){ mp[i]=mx>i?min(mp[(id<<1)-i],mx-i):1; while(ma[i+mp[i]]==ma[i-mp[i]])mp[i]++; if(mp[i]+i>mx){ mx=mp[i]+i; id=i; } ans=ans>mp[i]?ans:mp[i]; } printf("%d\n",ans-1); } int main(){ while(rds(str)!=EOF) Manacher(); return 0; } /* aaaa abab */