Bzoj 2565: Longest double palindrome

Source: Internet
Author: User

2565: Longest double palindrome time limit:10 Sec Memory limit:128 MB
submit:1769 solved:895
[Submit] [Status] [Discuss] Description sequence and reverse order read the exact same string called Palindrome string. For example, ACBCA is a palindrome string, and ABC is not (ABC's order is "ABC", Reverse is "CBA", not the same).
Enter the string s of length n, to find the longest double palindrome t of S, you can divide t into two parts x, Y, (| x|,| y|≥1) and X and Y are palindrome strings. Input

a line of string s consisting of lowercase English letters.

The output line is an integer representing the length of the longest double palindrome string. Sample InputBaacaabbacabb
Sample Output12
HINT

Sample Description

The string Aacaabbacabb starting from the second character can be divided into two parts, AACAA and Bbacabb, and both are palindrome strings.

For 100% of data, 2≤| S|≤10^5


2015.4.25 New Plus Data group

Source

2012 National Training Team Round 1 day2

Analysis:

First, use Manacher to find the longest palindrome that each point can extend, and then for each point record L[i]r[i] represents the longest palindrome length at the end or beginning of the current point ...

There are two ways to find LR ... One is my relatively low method of seeking ... One is lty big guy side do manacher side to seek LR%%% procedure ...

I will not say, look at the code ... Expressive Power 2333 ...

Lty said can be in manacher violent match time (that is the following sentence ...)

while (Str[i-p[i]]==str[i+p[i]]) p[i]++;

This time you can update the LR array of the point of violence extension ...%%%

Code:
1#include <algorithm>2#include <iostream>3#include <cstring>4#include <cstdio>5 //by Neighthorn6 using namespacestd;7 //facial features as ever, years as before8 9 Const intmaxn=200000+5;Ten  One intANS,LEN,P[MAXN],L[MAXN],R[MAXN]; A  - CharS[MAXN],STR[MAXN]; -  theInlinevoidPrework (void){ -     inti; -      for(i=0; s[i];i++) -str[2*i+1]='#', str[(i+1)*2]=S[i]; +len=2*i+1; str[0]='$'; str[len]=str[len+1]='#'; - } +  AInlinevoidManacher (void){ at     intid,mx=0; -      for(intI=1; i<len;i++){ -P[i]=i<mx?min (p[id*2-i],mx-i):1; -          while(str[i-p[i]]==str[i+P[i]]) -p[i]++; -         if(p[i]+i>mx) inMx=p[i]+i,id=i; -     } to } +  -Signed Main (void){ thescanf"%s", s); ans=0; * prework (); Manacher (); $      for(intI=1; i<=len;i++)Panax Notoginsengl[i-p[i]+1]=max (l[i-p[i]+1],p[i]-1), r[i+p[i]-1]=max (r[i+p[i]-1],p[i]-1); -      for(intI=1; i<=len;i++){ the         if(i&1) +L[i]=max (l[i],l[i-1]-2); A         Else theL[i]=max (l[i],l[i-1]); +     } -      for(intI=1; i<len;i++) $         if(l[i]&&R[i]) $Ans=max (ans,l[i]+r[i]); -printf"%d\n", ans); -     return 0; the}//The cap ou pas Cap. Pas Cap.

by Neighthorn

Bzoj 2565: Longest double palindrome

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.