BZOJ2565: Longest double palindrome string (palindrome tree)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.