CF1415B.Repainting Street

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There is a street with nn houses in a line, numbered from 11 to nn. The house ii is initially painted in color cic_i. The street is considered beautiful if all houses are painted in the same color. Tom, the painter, is in charge of making the street beautiful. Tom's painting capacity is defined by an integer, let's call it kk.

On one day, Tom can do the following repainting process that consists of two steps:

  1. He chooses two integers ll and rr such that $ 1 \le l \le r \le n $ and $ r - l + 1 = k $.
  2. For each house ii such that l≤i≤rl \le i \le r, he can either repaint it with any color he wants, or ignore it and let it keep its current color.

Note that in the same day Tom can use different colors to repaint different houses.

Tom wants to know the minimum number of days needed to repaint the street so that it becomes beautiful.

一条街道上有 nn 座房屋排成一行,编号从 11 到 nn。初始时,第 ii 座房屋被涂成颜色 cic_i。当所有房屋都被涂成同一种颜色时,该街道被认为是“美丽的”。汤姆(Tom)是一名粉刷匠,负责将这条街道变得美丽。汤姆的粉刷能力由一个整数定义,我们称之为 kk。

在一天之内,汤姆可以执行如下重涂操作,该操作包含两个步骤:

  1. 他选择两个整数 ll 和 rr,满足 $ 1 \le l \le r \le n $ 且 $ r - l + 1 = k $。
  2. 对于每个满足 l≤i≤rl \le i \le r 的房屋 ii,他可以选择将其重涂为任意颜色,也可以选择忽略它,使其保持当前颜色。

注意:在同一天内,汤姆可以对不同的房屋使用不同的颜色进行重涂。

汤姆想知道,使街道变得美丽所需的最少天数是多少?

输入格式

The first line of input contains a single integer tt ($ 1 \le t \le 10^4$), the number of test cases. Description of test cases follows.

In the first line of a test case description there are two integers nn and kk (1≤k≤n≤1051 \le k \le n \le 10^5).

The second line contains nn space-separated integers. The ii-th of these integers represents cic_i (1≤ci≤1001 \le c_i \le 100), the color which house ii is initially painted in.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤k≤n≤1051 \le k \le n \le 10^5)。

第二行包含 nn 个以空格分隔的整数。其中第 ii 个整数表示 cic_i(1≤ci≤1001 \le c_i \le 100),即第 ii 座房屋初始涂刷的颜色。

保证所有测试用例中 nn 的总和不超过 10510^5。

输出格式

Print tt lines, each with one integer: the minimum number of days Tom needs to make the street beautiful for each test case.

输出 tt 行,每行一个整数:对于每个测试用例,Tom 使街道变得美观所需的最少天数。

输入输出样例

  • 输入#1

    3
    10 2
    1 1 2 2 1 1 2 2 2 1
    7 1
    1 2 3 4 5 6 7
    10 3
    1 3 3 3 3 1 2 1 3 3

    输出#1

    3
    6
    2

说明/提示

In the first test case Tom should paint houses 1 and 2 in the first day in color 2, houses 5 and 6 in the second day in color 2, and the last house in color 2 on the third day.

In the second test case Tom can, for example, spend 6 days to paint houses 1, 2, 4, 5, 6, 7 in color 3.

In the third test case Tom can paint the first house in the first day and houses 6, 7, and 8 in the second day in color 3.

在第一个测试用例中,Tom 应在第一天将房屋 1 和 2 涂成颜色 2,第二天将房屋 5 和 6 涂成颜色 2,第三天将最后一栋房屋涂成颜色 2。

在第二个测试用例中,Tom 可以(例如)花费 6 天时间,将房屋 1、2、4、5、6、7 涂成颜色 3。

在第三个测试用例中,Tom 可以在第一天涂第一栋房屋,在第二天将房屋 6、7 和 8 涂成颜色 3。

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

首页