Up
Time Limit: 4000/2000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 7317 accepted submission (s): 2500
The Problem description is a string consisting of lowercase English characters a, B, c... Y, and Z. Evaluate the length of the longest return string in S.
The same string is used for both positive and negative reads, such as ABA and ABBA.
There are multiple input cases in each group. Each input is a string consisting of lowercase letters a, B, c... y, and z.
The two cases are separated by empty rows (this empty row does not need to be processed)
String Length Len <= 110000
An integer x in each line of output corresponds to a group of cases, which indicates the maximum length of the input string in the group of cases.
Sample Input
aaaaabab
Sample output
43
Source2009 multi-university training contest 16-host by nit
Recommendlcy | we have carefully selected several similar problems for you: 1358 1686 3336 3065 question: see Chinese. Idea: manacher bare question. This is mainly for exercises. For more information about the manacher algorithm, see here. The main idea is to add the separator to the string. Returns the same odd-even length of the input string to an odd-number input length. Obtain the maximum length of each character as the center character. The subsequent results use the previous results. P [I]-1 is the length of the original input string. For details, see the code:
# Include <iostream> # include <string. h> # include <stdio. h> using namespace STD; const int INF = 0x3f3f3f3f; const int maxn = 111000; int P [maxn <1], Len; char Buf [maxn], st [maxn <1]; void Init () {int I; Len = strlen (BUF); ST [0] = '$ ', st [1] = '#'; for (I = 0; I <Len; I ++) ST [2 * I + 2] = Buf [I], st [2 * I + 3] = '#'; Len = 2 * Len + 2;} void manacher () {int I, ID, MX = 0; for (I = 1; I <Len; I ++) {P [I] = Mx> I? Min (Mx-I, P [2 * ID-I]): 1; while (ST [I + P [I] = sT [I-P [I]) // you do not have to worry about crossing the border. Because st [0] = '$' p [I] ++; if (I + P [I]> MX) MX = I + P [I], id = I ;}} int main () {int I, ans; while (~ Scanf ("% s", Buf) {ans = 1; Init (); manacher (); for (I = 2; I <Len; I ++) ans = max (ANS, P [I]); printf ("% d \ n", ans-1);} return 0 ;}