CQUOJ 10672 Kolya and Tandem Repeat

A. Kolya and Tandem Repeat

Time Limit: 2000ms

Memory Limit: 262144KB

64-bit integer IO format: %I64d      Java class name: Any

Submit Status PID: 10672

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 Input

Input

aaba2

Output

6

Input

aaabbbb2

Output

6

Input

abracadabra10

Output

20

Hint

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.

 1 /*
 2 2016年4月22日00:01:53
 3
 4 题意:给出一个字符串,给出k,可以向该字符串尾部添加k个字符串,求最长的连续重复两次的子串
 5
 6     看了题解,可以先把这k个字符填成‘*‘,再暴力枚举起点和长度,找出最大的长度
 7 */
 8
 9 # include <iostream>
10 # include <cstdio>
11 # include <cstring>
12 # include <algorithm>
13 # include <queue>
14 # include <vector>
15 # define INF 0x3f3f3f3f
16 using namespace std;
17
18 int main(void)
19 {
20     char s[20005];
21     int n, len, i, j, k, flag, ans;
22     while (~scanf("%s %d", &s, &n)){
23         getchar();
24         len = strlen(s);
25         for (i = len; i < len+n; i++)
26             s[i] = ‘*‘;
27         len += n;
28         ans = -1;
29         for (i = 0; i < len; i++){
30             for (j = 1; 2*j+i<=len; j++){
31                 flag = 1;
32                 for (k = i; k < i+j; k++){
33                     if (s[k]!=s[k+j] && s[k+j]!=‘*‘){
34                         flag = 0;
35                         break;
36                     }
37                 }
38                 if (flag) ans = max(ans, 2*j);
39             }
40         }
41         printf("%d\n", ans);
42     }
43
44     return 0;
45 }
时间: 2024-10-05 04:44:58

CQUOJ 10672 Kolya and Tandem Repeat的相关文章

Codeforces 442B Kolya and Tandem Repeat(暴力)

题目连接:Codeforces 442B Kolya and Tandem Repeat 题目大意:给出一个字符串,可以再添加n个字符,问说可以找到SS的子串形式,S尽量长. 解题思路:枚举长度和起点判断即可,超过len的可以作为任意值,但是超过len+n就不行了. #include <cstdio> #include <cstring> const int N = 205; int n, len; char s[N]; bool judge (int l) { if (l <

Codeforces Round #253 (Div. 2) B - Kolya and Tandem Repeat

本题要考虑字符串本身就存在tandem, 如测试用例 aaaaaaaaabbb 3 输出结果应该是8而不是6,因为字符串本身的tanderm时最长的 故要考虑字符串本身的最大的tanderm和添加k个字符后最大的tanderm #include <iostream> #include <vector> #include <algorithm> #include <string> #include <set> using namespace std

CF B. Kolya and Tandem Repeat

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. H

Codeforces 443 B Kolya and Tandem Repeat【暴力】

题意:给出一个字符串,给出k,可以向该字符串尾部添加k个字符串,求最长的连续重复两次的子串 没有想出来= =不知道最后添加的那k个字符应该怎么处理 后来看了题解,可以先把这k个字符填成'*',再暴力枚举起点和长度,找出最大的长度 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<

CodeForces 443B Kolya and Tandem Repeat

题目:Click here 题意:给定一个字符串(只包含小写字母,并且最长200)和一个n(表示可以在给定字符串后面任意加n(<=200)个字符).问最长的一条子串长度,子串满足前半等于后半. 分析:暴力~~~~~~ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; const int M = 3e5+3; int k; char str[M];

暑假集训-个人赛第三场

ID Origin Title 10 / 29 Problem A CodeForces 443B Kolya and Tandem Repeat   1 / 1 Problem B CodeForces 442A Borya and Hanabi 9 / 29 Problem C CodeForces 442B Andrey and Problem 3 / 17 Problem D CodeForces 442C Artem and Array 14 / 18 Problem E CodeFo

Codeforces Round 253 (Div. 2)

layout: post title: Codeforces Round 253 (Div. 2) author: "luowentaoaa" catalog: true tags: mathjax: true - codeforces - 模拟栈 - 贪心 传送门 A.Anton and Letters (签到) 题意 判断字符串里面有多少个不同字符 思路 直接set一下 #include<bits/stdc++.h> using namespace std; typed

结核分歧菌_维基百科

http://en.wikipedia.org/wiki/Mycobacterium_tuberculosis the number of words: 3085word           count---------------------tuberculosis      64mycobacterium      23stain              5pathogen           5mycobacterial       5acid-fast          5staini

NET format

The net file format is used to describe the axtNet data that underlie the net alignment annotations in the Genome Browser. For a detailed description of the methods used to generate these data, refer to the Genome Browser description pages that accom