CF443B.Kolya and Tandem Repeat

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

科里亚生日时收到了一个字符串 ss,该字符串由小写英文字母组成。他立即在该字符串右侧添加了 kk 个额外字符。

随后鲍里亚指出,新字符串中包含一个长度为 ll 的并联重复子串(tandem repeat)。ll 的最大可能值是多少?

有关“并联重复”的定义,请参见注释部分。

输入格式

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.

第一行包含字符串 ss(1 ≤ ∣s∣ ≤ 2001 \le |s| \le 200)。该字符串仅由小写英文字母组成。第二行包含整数 kk(1 ≤ k ≤ 2001 \le k \le 200)——待添加的字符个数。

输出格式

Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.

输出一个整数——新字符串中可能出现的并联重复(tandem repeat)的最大长度。

输入输出样例

  • 输入#1

    aaba
    2

    输出#1

    6
  • 输入#2

    aaabbbb
    2

    输出#2

    6
  • 输入#3

    abracadabra
    10

    输出#3

    20

说明/提示

A tandem repeat of length 2_n_ is string s, where for any position i (1 ≤ i ≤ n) the following condition fulfills: s__i = s__i + n.

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

长度为 2n2n 的并列重复串(tandem repeat)是指字符串 ss,使得对任意位置 ii(1≤i≤n1 \le i \le n),均满足:si=si+ns_i = s_{i+n}。

在第一个样例中,Kolya 可以得到字符串 aabaab;在第二个样例中,可得到 aaabbbbbb;在第三个样例中,可得到 abracadabrabracadabra。

输入解题思路,AI测评打分。不知道怎么写?

首页