CF371A.K-Periodic Array

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.

Array aa is kk -period if its length is divisible by kk and there is such array bb of length kk , that aa is represented by array bb written exactly times consecutively. In other words, array aa is kk -periodic, if it has period of length kk .

For example, any array is nn -periodic, where nn is the array length. Array [2,1,2,1,2,1][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][1,2,1,1,2,1,1,2,1] is at the same time 3-periodic and 9-periodic.

For the given array aa , consisting only of numbers one and two, find the minimum number of elements to change to make the array kk -periodic. If the array already is kk -periodic, then the required value equals 00 .

输入格式

The first line of the input contains a pair of integers nn , kk ( 1<=k<=n<=100)1<=k<=n<=100) , where nn is the length of the array and the value nn is divisible by kk . The second line contains the sequence of elements of the given array a1,a2,...,ana_{1},a_{2},...,a_{n} ( 1<=ai<=21<=a_{i}<=2 ), aia_{i} is the ii -th element of the array.

输出格式

Print the minimum number of array elements we need to change to make the array kk -periodic. If the array already is kk -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][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][1,1,1,1,1,1,1,1,1] — this array is simultaneously 1-, 3- and 9-periodic.

首页