CF 443B(253B)Kolya and Tandem Repeat

来源:互联网 发布:apache storm 源码 编辑:程序博客网 时间:2024/06/05 15:14

Kolya and Tandem Repeat
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Kolya got string s for his birthday, the string consists of small English letters. He immediately addedk more characters to the right of the string.

Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large couldl be?

See notes for definition of a tandem repeat.

Input

The first line contains s (1 ≤ |s| ≤ 200). This string contains only small English letters. The second line contains numberk (1 ≤ k ≤ 200) — the number of the added characters.

Output

Print a single number — the maximum length of the tandem repeat that could 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 2n is string s, where for any position i (1 ≤ i ≤ n) the following condition fulfills:si = si + n.

In the first sample Kolya could obtain a string aabaab, in the second — aaabbbbbb, in the third —abracadabrabracadabra


枚举吧,字符不长。


AC代码如下:


#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;}//特别记住这种情况    int max=0;    for(i=0;i<l;i++)//字符的起始    {        for(j=1;j<=l-i;j++)//枚举字符的长度        {            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)//验证符合否              max=2*ans;        }    }    cout<<max<<endl;    return 0;}



2 0
原创粉丝点击