CF1332C.K-Complete Word
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Word s of length n is called k -complete if
- s is a palindrome, i.e. si=sn+1−i for all 1≤i≤n ;
- s has a period of k , i.e. si=sk+i for all 1≤i≤n−k .
For example, "abaaba" is a 3 -complete word, while "abccba" is not.
Bob is given a word s of length n consisting of only lowercase Latin letters and an integer k , such that n is divisible by k . He wants to convert s to any k -complete word.
To do this Bob can choose some i ( 1≤i≤n ) and replace the letter at position i with some other lowercase Latin letter.
So now Bob wants to know the minimum number of letters he has to replace to convert s to any k -complete word.
Note that Bob can do zero changes if the word s is already k -complete.
You are required to answer t test cases independently.
输入格式
The first line contains a single integer t ( 1≤t≤105 ) — the number of test cases.
The first line of each test case contains two integers n and k ( 1≤k<n≤2⋅105 , n is divisible by k ).
The second line of each test case contains a word s of length n .
It is guaranteed that word s only contains lowercase Latin letters. And it is guaranteed that the sum of n over all test cases will not exceed 2⋅105 .
输出格式
For each test case, output one integer, representing the minimum number of characters he has to replace to convert s to any k -complete word.
输入输出样例
输入#1
4 6 2 abaaba 6 3 abaaba 36 9 hippopotomonstrosesquippedaliophobia 21 7 wudixiaoxingxingheclp
输出#1
2 0 23 16
说明/提示
In the first test case, one optimal solution is aaaaaa.
In the second test case, the given word itself is k -complete.