Kolya and Tandem Repeat

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 added k 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 could l 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 number k (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
aaba
2
output
6
input
aaabbbb
2
output
6
input
abracadabra
10
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.

比赛的时候,题目意思没看懂,理解错误,一直没做出来,真是悲剧。外语水平太差了。

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;

char str[3333];
int fla[999];
int main(void)
{
    int i,j,n,m,k,maxx=-1;
    gets(str);
    cin>>k;
    int len=strlen(str);
    if(k>=len)
        printf("%d\n",(k+len)/2*2);
    else
    {
    n=len+k;
    for(i=0;i<len;i++)
    {
        for(j=1;j<=len-i;j++)
        {
            int ans=0;
            for(int kk=i;kk<i+j;kk++)
            {
                if(kk+j>=len&&kk+j<n)
                    ans++;
                else if(str[kk]==str[kk+j])
                    ans++;
            }
            if(ans==j)//这里之前忘了写了。。。
            maxx=max(ans,maxx);
        }
    }
    cout<<maxx*2<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值