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