Kolya and Tandem Repeattime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
Kolya got stringSFor his birthday, the string consists of small English letters. He immediately addedKMore characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of lengthLAs a substring. How large cocouldLBe?
See notes for definition of a tandem repeat.
Input
The first line containsS(1 hour ≤ hour |S| Limit ≤ limit 200). This string contains only small English letters. The second line contains numberK(1 digit ≤ DigitKLimit ≤ limit 200)-the number of the added characters.
Output
Print a single number-the maximum length of the tandem repeat that cocould have occurred in the new string.
Sample test (s) Input
aaba2
Output
6
Input
aaabbbb2
Output
6
Input
abracadabra10
Output
20
Note
A tandem repeat of length 2NIs stringS, Where for any positionI(1 digit ≤ DigitILimit ≤ limitN) The following condition fulfills:SISignature = SignatureSIRegion + RegionN.
In the first sample Kolya cocould obtain a string aabaab, in the second-aaabbbbbb, in the third-abracadabrabracadabra
Enumerative. The characters are not long.
The AC code is as follows:
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # define M 100005 # define ll long longusing namespace std; int main () {char a [10005]; int k; cin> a> k; int l = strlen (a); int I, m, j, o, ans; m = l + k; m = m-m % 2; if (k> = l) {cout <m <endl; return 0 ;} // remember this case int max = 0; for (I = 0; I <l; I ++) // start of the character {for (j = 1; j <= l-I; j ++) // length of the enumerated characters {for (o = I, ans = 0; o <I + j; o ++) {if (o + j> = l & o + j <l + k) ans ++; else if (a [o] = a [o + j]) ans ++;} if (ans = j & 2 * ans> max) // check whether the compliance is true. max = 2 * ans ;}} cout <max <endl; return 0 ;}