#P16837. [GKS 2021 #A] K-Goodness String
[GKS 2021 #A] K-Goodness String
Problem Description
Charles defines the goodness score of a string as the number of indices such that where (-indexed). For example, the string CABABC has a goodness score of since and .
Charles gave Ada a string of length , consisting of uppercase letters and asked her to convert it into a string with a goodness score of . 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 ?
Input Format
The first line of the input gives the number of test cases, . test cases follow.
The first line of each test case contains two integers and . The second line of each test case contains a string of length , consisting of uppercase letters.
Output Format
For each test case, output one line containing Case #x: y, where is the test case number (starting from ) and is the minimum number of operations required to transform the given string into a string with goodness score equal to .
2
5 1
ABCAA
4 2
ABAA
Case #1: 0
Case #2: 1
Hint
In Sample Case #, the given string already has a goodness score of . Therefore the minimum number of operations required is .
In Sample Case #, one option is to change the character at index to B in order to have a goodness score of . Therefore, the minimum number of operations required is .
Limits
.
.
Test Set
.
Test Set
for at most test cases.
For the remaining cases, .