CF371A.K-Periodic Array

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

本题仅考虑所有元素均为 1 和/或 2 的数组。

若数组 $ a $ 的长度能被 $ k $ 整除,且存在一个长度为 $ k $ 的数组 $ b $,使得 $ a $ 恰好由 $ b $ 连续重复 次构成,则称数组 $ a $ 是 $ k $-周期的。换言之,若数组 $ a $ 具有长度为 $ k $ 的周期,则称其为 $ k $-周期的。

例如,任意数组都是 $ n $-周期的,其中 $ n $ 为该数组的长度。数组 [2, 1, 2, 1, 2, 1][2,\,1,\,2,\,1,\,2,\,1] 同时是 2-周期的和 6-周期的;数组 [1, 2, 1, 1, 2, 1, 1, 2, 1][1,\,2,\,1,\,1,\,2,\,1,\,1,\,2,\,1] 同时是 3-周期的和 9-周期的。

给定一个仅由数字 1 和 2 构成的数组 $ a $,求使其变为 $ k $-周期数组所需修改的最少元素个数。若该数组本身已是 $ k $-周期的,则答案为 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.

输入的第一行包含一对整数 nn、kk(1 ≤ k ≤ n ≤ 1001 ≤ k ≤ n ≤ 100),其中 nn 是数组的长度,且 nn 能被 kk 整除。第二行包含给定数组的元素序列 a1, a2, ..., ana_1, a_2, ..., a_n(1 ≤ ai ≤ 21 ≤ a_i ≤ 2),其中 aia_i 表示数组的第 ii 个元素。

输出格式

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.

输出使数组变为 k-周期性所需修改的数组元素的最少个数。如果数组已经是 k-周期性的,则输出 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.

在第一个样例中,只需将第四个元素从 2 改为 1,数组即变为 [2, 1, 2, 1, 2, 1]。

在第二个样例中,给定的数组本身已是 4-周期性的。

在第三个样例中,只需将所有数字 2 替换为数字 1 即可。此时数组变为 [1, 1, 1, 1, 1, 1, 1, 1, 1] —— 该数组同时是 1-、3- 和 9-周期性的。

输入解题思路,AI测评打分。不知道怎么写?

首页