标签:int define str clu max while man turn nan
Code:
#include <cstdio> #include <algorithm> #include <cstring> #define setIO(s) freopen(s".in","r",stdin) #define maxn 10001000 using namespace std; char s[maxn],str[maxn]; int p[maxn]; int Init(){ int len=strlen(s); str[0]=‘$‘,str[1]=‘#‘; int j=1; for(int i=0;i<len;++i) str[++j]=s[i],str[++j]=‘#‘; str[++j]=‘\0‘; return j; } int Manancher(){ int len=Init(),maxv=0,id=1,mx=1; for(int i=1;i<len;++i){ if(mx>i) p[i]=min(p[2*id-i],mx-i); else p[i]=1; while(str[i-p[i]]==str[i+p[i]]) p[i]++; if(mx<i+p[i]) id=i,mx=i+p[i]; maxv=max(maxv,p[i]-1); } return maxv; } int main(){ int n; scanf("%d",&n); while(n--){ memset(p,0,sizeof(p)); scanf("%s",s); printf("%d\n",Manancher()); } return 0; }
标签:int define str clu max while man turn nan
原文地址:https://www.cnblogs.com/guangheli/p/10264854.html