标签:
/* 裸地manachar */ #include<iostream> #include<cstdio> #include<cstring> #define maxn 1000010 using namespace std; int l,len[maxn]; char s[maxn],ss[maxn]; int manachar() { int ans=0; int id=-1,mx=-1; for(int i=1;i<=l;i++) { if(id+mx-i>=0) len[i]=min(id+mx-i,len[id*2-i]); while(i-len[i]-1>=0&&i+len[i]+1<=l&&s[i-len[i]-1]==s[i+len[i]+1]) len[i]++; if(i+len[i]>id+mx) { id=i;mx=len[i]; } ans=max(ans,len[i]); } return ans; } int main() { int cas=0; while(scanf("%s",ss)) { if(strcmp(ss,"END")==0)break; l=strlen(ss); memset(len,0,sizeof(len)); for(int i=0;i<l;i++) { s[i*2+1]=ss[i]; s[i*2+2]=‘#‘; } l=l*2; s[0]=‘#‘; manachar(); printf("Case %d: %d\n",++cas,manachar()); } return 0; }
标签:
原文地址:http://www.cnblogs.com/yanlifneg/p/5475431.html