CF1746A.Maxmina

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have an array aa of size nn consisting only of zeroes and ones and an integer kk. In one operation you can do one of the following:

  • Select 22 consecutive elements of aa and replace them with their minimum (that is, let a:=[a1,a2,…,ai−1,min⁡(ai,ai+1),ai+2,…,an]a := [a_{1}, a_{2}, \ldots, a_{i-1}, \min(a_{i}, a_{i+1}), a_{i+2}, \ldots, a_{n}] for some 1≤i≤n−11 \le i \le n-1). This operation decreases the size of aa by 11.
  • Select kk consecutive elements of aa and replace them with their maximum (that is, let a:=[a1,a2,…,ai−1,max⁡(ai,ai+1,…,ai+k−1),ai+k,…,an]a := [a_{1}, a_{2}, \ldots, a_{i-1}, \max(a_{i}, a_{i+1}, \ldots, a_{i+k-1}), a_{i+k}, \ldots, a_{n}] for some 1≤i≤n−k+11 \le i \le n-k+1). This operation decreases the size of aa by k−1k-1.

Determine if it's possible to turn aa into [1][1] after several (possibly zero) operations.

你有一个长度为 nn 的数组 aa,其中仅包含 00 和 11,以及一个整数 kk。在一次操作中,你可以执行以下两种操作之一:

  • 选取 aa 中两个相邻的元素,并将其替换为它们的最小值(即,对某个满足 1≤i≤n−11 \le i \le n-1 的下标 ii,令 a:=[a1,a2,…,ai−1,min⁡(ai,ai+1),ai+2,…,an]a := [a_{1}, a_{2}, \ldots, a_{i-1}, \min(a_{i}, a_{i+1}), a_{i+2}, \ldots, a_{n}])。该操作使数组 aa 的长度减少 11。
  • 选取 aa 中 kk 个相邻的元素,并将其替换为它们的最大值(即,对某个满足 1≤i≤n−k+11 \le i \le n-k+1 的下标 ii,令 a:=[a1,a2,…,ai−1,max⁡(ai,ai+1,…,ai+k−1),ai+k,…,an]a := [a_{1}, a_{2}, \ldots, a_{i-1}, \max(a_{i}, a_{i+1}, \ldots, a_{i+k-1}), a_{i+k}, \ldots, a_{n}])。该操作使数组 aa 的长度减少 k−1k-1。

判断是否可以通过若干次(可以为零次)上述操作,将 aa 变为 [1][1]。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10001 \le t \le 1000). The description of the test cases follows.

The first line of each test case contains two integers nn and kk (2≤k≤n≤502 \le k \le n \le 50), the size of array aa and the length of segments that you can perform second type operation on.

The second line contains nn integers a1,a2,…,ana_{1}, a_{2}, \ldots, a_{n} (aia_i is 00 or 11), elements of array aa.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤10001 \le t \le 1000)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 kk(2≤k≤n≤502 \le k \le n \le 50),分别表示数组 aa 的大小以及可对之执行第二种操作的区间的长度。

第二行包含 nn 个整数 a1,a2,…,ana_{1}, a_{2}, \ldots, a_{n}(每个 aia_i 为 00 或 11),即数组 aa 的元素。

输出格式

For each test case, if it is possible to turn aa into [1][1], print "YES", otherwise print "NO".

对于每个测试用例,如果可以将 aa 变为 [1][1],则输出 "YES";否则输出 "NO"。

输入输出样例

  • 输入#1

    7
    3 2
    0 1 0
    5 3
    1 0 1 1 0
    2 2
    1 1
    4 4
    0 0 0 0
    6 3
    0 0 1 0 0 1
    7 5
    1 1 1 1 1 1 1
    5 3
    0 0 1 0 0

    输出#1

    YES
    YES
    YES
    NO
    YES
    YES
    YES

说明/提示

In the first test case, you can perform the second type operation on second and third elements so aa becomes [0,1][0, 1], then you can perform the second type operation on first and second elements, so aa turns to [1][1].

In the fourth test case, it's obvious to see that you can't make any 11, no matter what you do.

In the fifth test case, you can first perform a type 2 operation on the first three elements so that aa becomes [1,0,0,1][1, 0, 0, 1], then perform a type 2 operation on the elements in positions two through four, so that aa becomes [1,1][1, 1], and finally perform the first type operation on the remaining elements, so that aa becomes [1][1].

在第一个测试用例中,你可以对第二个和第三个元素执行第二种类型的操作,使 aa 变为 [0,1][0, 1];然后对第一个和第二个元素执行第二种类型的操作,使 aa 变为 [1][1]。

在第四个测试用例中,显然无论你如何操作,都无法得到任何 11。

在第五个测试用例中,你可以首先对前三个元素执行一次类型 2 的操作,使 aa 变为 [1,0,0,1][1, 0, 0, 1];接着对位置二至四的元素执行一次类型 2 的操作,使 aa 变为 [1,1][1, 1];最后对剩余的元素执行一次类型 1 的操作,使 aa 变为 [1][1]。

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

首页