a370: K-Goodness String
Tags : 字串 循環
Accepted rate : 19人/21人 ( 90% ) [非即時]
評分方式:
Strictly

最近更新 : 2021-06-11 12:29

Content

Problem

Charles defines the goodness score of a string as the number of indices i such that S≠ Sn-i+1 where 1 ≤ i ≤ N/2 (1-indexed). For example, the string CABABC has a goodness score of 2 since S≠ S5 and S≠ S4.

Charles gave Ada a string S of length N, consisting of uppercase letters and asked her to convert it into a string with a goodness score of K. In one operation, Ada can change any character in the string to any uppercase letter. Could you help Ada find the minimum number of operations required to transform the given string into a string with goodness score equal to K?

 

Limits

Memory limit: 1 GB.
1 ≤ T ≤ 100.
0 ≤ K ≤ N/2.

Test Set 1

Time limit: 20 seconds.
1 ≤ N ≤ 100.

Test Set 2

Time limit: 40 seconds.
1 ≤ N ≤ 2×105 for at most 10 test cases.
For the remaining cases, 1 ≤ N ≤ 100.

Input

The first line of the input gives the number of test cases, T. T test cases follow.

The first line of each test case contains two integers N and K. The second line of each test case contains a string S of length N, consisting of uppercase letters.

Output

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the minimum number of operations required to transform the given string S into a string with goodness score equal to K.

Sample Input #1
2
5 1
ABCAA
4 2
ABAA
Sample Output #1
Case #1: 0
Case #2: 1
測資資訊:
記憶體限制: 64 MB
不公開 測資點#0 (33%): 1.0s , <1K
不公開 測資點#1 (33%): 1.0s , <1M
不公開 測資點#2 (34%): 1.0s , <10M
Hint :
Tags:
字串 循環
出處:
Kick Start 2021 Round A [管理者:
lamkinun@gma... (Kinda Lam)
]


ID User Problem Subject Hit Post Date
沒有發現任何「解題報告」