"BZOJ2342" "Shoi2011" double palindrome manacher+ enumeration + optimality Pruning

Source: Internet
Author: User

The Manacher treatment of the palindrome radius, and then know a palindrome string can be known on both sides of the palindrome Center, and then O (1) Check whether it is legal, that is to judge the center of the two sides of the palindrome radius.


Here we need to enumerate the palindrome radius for each location, because for example this

18
Abbbaabbbaccddddcc

CCDDDDCC is not double palindrome, but there is a dddd in the middle is double palindrome, if each palindrome only check the longest is not double palindrome, will WA here.

Manacher algorithm: http://blog.csdn.net/vmurder/article/details/42119417

So you need to enumerate:

Paste code: (I put the code slightly reduced line, WA left message me)

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 501000using namespace Std;char ts[n],s[n<<1];int n,len,p[n<<1];void manacher () {int i,j,k,mx=0,id;scanf (" %s ", ts+1);/*n=strlen (ts+1), */len=n*2+1;s[0]= ' * ', s[1]= ' ~ '; for (i=1;i<=n;i++) s[i*2]=ts[i],s[i*2+1]= ' ~ '; for (i=1 ; i<=len;i++) {if (mx>i) p[i]=min (p[id*2-i],mx-i); else P[i]=1;while (S[i-p[i]]==s[i+p[i]]) p[i]++;if (mx<i+p[ I]) mx=i+p[i],id=i;} return;} int main () {scanf ("%d", &n), Manacher (); int ans=0;for (int i=1;i<=len;i+=2) {for (int j= ((p[i]-1) >>1)-(j &1); j>0&&j*2>ans;j-=2) if (p[i-j]-1>=j&&p[i+j]-1>=j) Ans=max (ans,2*j);} printf ("%d\n", ans); return 0;}


Copy to Google TranslateTranslation Results

"BZOJ2342" "Shoi2011" double palindrome manacher+ enumeration + optimality Pruning

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.