标签:ret arc const des href iostream case 回文串 关于
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 24799 Accepted Submission(s): 9148
代码:
贴manacher模板
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int MAXN=110000; char s[MAXN+9],ma[MAXN*3+9]; int p[MAXN*3+9]; int manacher() { int len=0; ma[len++]=‘$‘; ma[len++]=‘#‘; int n=strlen(s); for(int i=0;i<n;i++){ ma[len++]=s[i]; ma[len++]=‘#‘; } int ans=0; for(int i=0,mx=0,id=0;i<len;i++){ p[i]=(mx>i?min(p[2*id-i],mx-i):1);//(id-(i-id))是i关于id对称的点 while(ma[i+p[i]]==ma[i-p[i]]) p[i]++; if(i+p[i]>mx) mx=i+p[i],id=i; ans=max(ans,p[i]-1); } return ans; } int main() { while(scanf("%s",s)==1){ printf("%d\n",manacher()); } return 0; }
标签:ret arc const des href iostream case 回文串 关于
原文地址:http://www.cnblogs.com/--ZHIYUAN/p/7944666.html