#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long
const int N=20005;
char s[N+5];
int dp[N*2+5];
char str[N*2+5];
int Manacher(char *s){
int n=0,len=strlen(s+1);
str[0]='$';
for(int i=1;i<=len;i++){
str[++n]='#';
str[++n]=s[i];
}
str[++n]='#',str[++n]='@';
int r=0,pos=0;
for(int i=1;i<=n;i++){
if(i<r)
dp[i]=min(dp[2*pos-i],r-i);
else dp[r=i]=1;
while(str[i-dp[i]]==str[i+dp[i]])dp[i]++;
if(i+dp[i]>r)r=i+dp[i],pos=i;
}
int ret=0;
for(int i=1;i<=n;i++){
ret=max(ret,dp[i]-1);
}
return ret;
}
int main(){
while(~scanf("%s",s+1)){
cout<<Manacher(s)<<endl;
}
}
03-13
1957
08-18
242
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交