-
Total time limit:
-
10000ms
-
Single test point time limit:
-
1000ms
-
Memory Limit:
-
5120000kB
-
-
Describe
-
-
A string s consisting of a lowercase English character a,b,c...y,z is given, and the length of the longest palindrome in S is obtained.
Palindrome is the same as the inverse of the string, such as ABA, ABBA, etc.
-
-
Input
-
-
a file a set of data
string s consisting of one line of lowercase English characters for each set of input a,b,c...y,z
String length len <= 110000
-
-
Output
-
-
An integer x that represents the longest palindrome length contained in the string.
-
-
Sample input
-
-
AAAA-------------//Ignore split line Abab
-
-
Sample output
-
4-------------3
1 /*2 Naked Manache Consider three cases3 */4#include <cstdio>5#include <cstring>6#include <iostream>7 #defineMAXN 1100108 9 using namespacestd;Ten One CharS[MAXN]; A - intL,l,ans; - the intt[maxn*3],len[maxn*3]; - -Inlinevoidinit () { -t[l++]='$'; +t[l++]='#'; - for(intI=0; i<l;i++) { +t[l++]=S[i]; At[l++]='#'; at } -t[l]=0; - return; - } - -InlinevoidManache () { in intp=0, p0=0; - for(intI=1; i<=l;i++) { to if(p>i) Len[i]=min (len[2*p0-i],p-i); + Elselen[i]=1; - while(T[i-len[i]]==t[i+len[i]]) len[i]++; the if(len[i]+i>p) { *p=len[i]+i; $p0=i;Panax Notoginseng } -Ans=max (ans,len[i]-1); the } + return; A } the + intMain () { - while(cin>>s) { $l=l=ans=0; $L=strlen (s); - if(! L Break; - init (); the Manache (); -printf"%d\n", ans);Wuyi } the return 0; -}
Code
"2012.07.11" the longest palindrome--horse-drawn vehicle algorithm