1089 Maximum palindrome substring V2 (manacher algorithm) base time limit: 1 seconds space limit: 131072 KB score: 0 Difficulty: Basic problem collection concern Palindrome string refers to Aba, ABBA, CCCBCCC, AAAA, the symmetry of the left and right strings. Enter a string str to output the length of the longest palindrome substring in str. Input
Input str (str length <= 100000)
Output
Outputs the length of the longest palindrome substring L.
Input example
Daabaac
Output example
5
#include <stdio.h>
#include <string.h>
char s[200010];int p[200010];
int min (int a,int b)
{
return a<b?a:b;
}
void f ()
{
int l=strlen (s);
for (int i=l;0<i;i--)
{
s[i*2+1]= ' # ';
S[I*2]=S[I-1];
}
S[0]= ' * ', s[1]= ' # ';
}
int Manacher ()
{
f ();
int mx = 0, id = 0,max=1;
memset (p, 0, sizeof (p));
for (int i = 1; s[i]! = i++)
{
p[i] = mx > I min (p[2 * id-i], mx-i): 1;
while (S[i + p[i]] = = S[i-p[i]])
p[i]++;
if (i + p[i] > mx)
{
mx = i + p[i];
id = i;
}
max=max>p[i]?max:p[i];
}
return max-1;
}
int main ()
{
int l,i;
while (scanf ("%s", s)!=eof)
printf ("%d\n", Manacher ());
return 0;
}