Title: http://www.lydsy.com/JudgeOnline/problem.php?id=2565
Record the longest extension of each point forward, both positive and negative, and enumerate the split points.
#include <cstring>#include<iostream>#include<algorithm>#include<cstdio>#defineRep (i,l,r) for (int i=l;i<=r;i++)#defineDown (i,l,r) for (int i=l;i>=r;i--)#defineCLR (x, y) memset (x,y,sizeof (×))#definell Long Long#defineMAXN 100500using namespacestd;intlen[maxn],cnt[maxn],p1[maxn],p2[maxn],fail[maxn],s[maxn],to[maxn][ -];intN,ans,tot,last,l,len1,len2;CharCH1[MAXN],CH2[MAXN];voidinit () {Len[tot=0]=0; len[++tot]=-1; fail[0]=1; s[n=0]=-1; last=0; CLR (To,0);}voidAddintCintp[]) {s[++n]=C; intTmp,cur,now; for(cur=last;s[n-len[cur]-1]!=c;cur=Fail[cur]); if(!To[cur][c]) {len[++tot]=len[cur]+2; now=tot; for(tmp=fail[cur];s[n-len[tmp]-1]!=c;tmp=fail[tmp]); Fail[now]=To[tmp][c]; TO[CUR][C]=Now ; } Last=To[cur][c]; Cnt[last]++; P[n]=n-len[last]+1;}intMain () {scanf ("%s", CH1); L=strlen (CH1); Rep (I,0, L-1) ch2[l-1-i]=Ch1[i]; Init (); Rep (I,0, L-1) Add (ch1[i]-'a', p1); Init (); Rep (I,0, L-1) Add (ch2[i]-'a', p2); Rep (I,0, L-1) {len1=i-p1[i]+1; Len2=l-i-p2[l-i]+1; Ans=max (ans,len1+len2); } printf ("%d\n", ans); return 0;}
BZOJ2565: Longest double palindrome string (palindrome tree)