A9172 | K-Periodic Array
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.
Array $a$ is $k$ -period if its length is divisible by $k$ and there is such array $b$ of length $k$ , that $a$ is represented by array $b$ written exactly  times consecutively. In other words, array $a$ is $k$ -periodic, if it has period of length $k$ .
For example, any array is $n$ -periodic, where $n$ is the array length. Array $[2,1,2,1,2,1]$ is at the same time 2-periodic and 6-periodic and array $[1,2,1,1,2,1,1,2,1]$ is at the same time 3-periodic and 9-periodic.
For the given array $a$ , consisting only of numbers one and two, find the minimum number of elements to change to make the array $k$ -periodic. If the array already is $k$ -periodic, then the required value equals $0$ .
Array $a$ is $k$ -period if its length is divisible by $k$ and there is such array $b$ of length $k$ , that $a$ is represented by array $b$ written exactly  times consecutively. In other words, array $a$ is $k$ -periodic, if it has period of length $k$ .
For example, any array is $n$ -periodic, where $n$ is the array length. Array $[2,1,2,1,2,1]$ is at the same time 2-periodic and 6-periodic and array $[1,2,1,1,2,1,1,2,1]$ is at the same time 3-periodic and 9-periodic.
For the given array $a$ , consisting only of numbers one and two, find the minimum number of elements to change to make the array $k$ -periodic. If the array already is $k$ -periodic, then the required value equals $0$ .
输入格式
The first line of the input contains a pair of integers $n$ , $k$ ( $1<=k<=n<=100)$ , where $n$ is the length of the array and the value $n$ is divisible by $k$ . The second line contains the sequence of elements of the given array $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=2$ ), $a_{i}$ is the $i$ -th element of the array.
输出格式
Print the minimum number of array elements we need to change to make the array $k$ -periodic. If the array already is $k$ -periodic, then print 0.
输入输出样例
输入 #1
6 2 2 1 2 2 2 1
输出 #1
1
输入 #2
8 4 1 1 2 1 1 1 2 1
输出 #2
0
输入 #3
9 3 2 1 1 1 2 1 1 1 2
输出 #3
3
In the first sample it is enough to change the fourth element from 2 to 1, then the array changes to $[2,1,2,1,2,1]$ .
In the second sample, the given array already is 4-periodic.
In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as $[1,1,1,1,1,1,1,1,1]$ — this array is simultaneously 1-, 3- and 9-periodic.
In the second sample, the given array already is 4-periodic.
In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as $[1,1,1,1,1,1,1,1,1]$ — this array is simultaneously 1-, 3- and 9-periodic.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted