A13268 | K-Complete Word
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Word $s$ of length $n$ is called $k$ -complete if
- $s$ is a palindrome, i.e. $s_i=s_{n+1-i}$ for all $1 \le i \le n$ ;
- $s$ has a period of $k$ , i.e. $s_i=s_{k+i}$ for all $1 \le i \le 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 \le i \le 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.
- $s$ is a palindrome, i.e. $s_i=s_{n+1-i}$ for all $1 \le i \le n$ ;
- $s$ has a period of $k$ , i.e. $s_i=s_{k+i}$ for all $1 \le i \le 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 \le i \le 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 \le t\le 10^5$ ) — the number of test cases.
The first line of each test case contains two integers $n$ and $k$ ( $1 \le k < n \le 2 \cdot 10^5$ , $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 \cdot 10^5$ .
The first line of each test case contains two integers $n$ and $k$ ( $1 \le k < n \le 2 \cdot 10^5$ , $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 \cdot 10^5$ .
输出格式
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.
In the second test case, the given word itself is $k$ -complete.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted