CF1710A.Color the Picture

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A picture can be represented as an n×mn\times m grid (nn rows and mm columns) so that each of the n⋅mn \cdot m cells is colored with one color. You have kk pigments of different colors. You have a limited amount of each pigment, more precisely you can color at most aia_i cells with the ii-th pigment.

A picture is considered beautiful if each cell has at least 33 toroidal neighbors with the same color as itself.

Two cells are considered toroidal neighbors if they toroidally share an edge. In other words, for some integers 1≤x1,x2≤n1 \leq x_1,x_2 \leq n and 1≤y1,y2≤m1 \leq y_1,y_2 \leq m, the cell in the x1x_1-th row and y1y_1-th column is a toroidal neighbor of the cell in the x2x_2-th row and y2y_2-th column if one of following two conditions holds:

  • x1−x2≡±1(modn)x_1-x_2 \equiv \pm1 \pmod{n} and y1=y2y_1=y_2, or
  • y1−y2≡±1(modm)y_1-y_2 \equiv \pm1 \pmod{m} and x1=x2x_1=x_2.

Notice that each cell has exactly 44 toroidal neighbors. For example, if n=3n=3 and m=4m=4, the toroidal neighbors of the cell (1,2)(1, 2) (the cell on the first row and second column) are: (3,2)(3, 2), (2,2)(2, 2), (1,3)(1, 3), (1,1)(1, 1). They are shown in gray on the image below:

The gray cells show toroidal neighbors of (1,2)(1, 2).

Is it possible to color all cells with the pigments provided and create a beautiful picture?

一幅图像可以表示为一个 n×mn\times m 的网格(nn 行、mm 列),其中 n⋅mn \cdot m 个单元格中的每一个均被染成一种颜色。你有 kk 种不同颜色的颜料,且每种颜料的数量有限:具体而言,第 ii 种颜料最多可给 aia_i 个单元格上色。

若图像中每个单元格都至少有 33 个环面邻接单元格(toroidal neighbor)与其颜色相同,则该图像被称为“优美的”。

两个单元格被称为环面邻接单元格,当且仅当它们在环面上共享一条边。换言之,对任意整数 1≤x1,x2≤n1 \leq x_1,x_2 \leq n 和 1≤y1,y2≤m1 \leq y_1,y_2 \leq m,位于第 x1x_1 行、第 y1y_1 列的单元格与位于第 x2x_2 行、第 y2y_2 列的单元格互为环面邻接单元格,当且仅当满足以下两个条件之一:

  • x1−x2≡±1(modn)x_1-x_2 \equiv \pm1 \pmod{n} 且 y1=y2y_1=y_2,或
  • y1−y2≡±1(modm)y_1-y_2 \equiv \pm1 \pmod{m} 且 x1=x2x_1=x_2。

注意:每个单元格恰好有 44 个环面邻接单元格。例如,当 n=3n=3 且 m=4m=4 时,单元格 (1,2)(1, 2)(即第 11 行、第 22 列的单元格)的环面邻接单元格为:(3,2)(3, 2)、(2,2)(2, 2)、(1,3)(1, 3)、(1,1)(1, 1)。如下图中灰色单元格所示:

灰色单元格表示 (1,2)(1, 2) 的环面邻接单元格。

能否使用所给颜料为所有单元格上色,从而构造出一幅优美的图像?

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \leq t \leq 10^4). The description of the test cases follows.

The first line of each test case contains three integers nn, mm, and kk (3≤n,m≤1093 \leq n,m \leq 10^9, 1≤k≤1051 \leq k \leq 10^5) — the number of rows and columns of the picture and the number of pigments.

The next line contains kk integers a1,a2,…,aka_1,a_2,\dots, a_k (1≤ai≤1091 \leq a_i \leq 10^9) — aia_i is the maximum number of cells that can be colored with the ii-th pigment.

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

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \leq t \leq 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含三个整数 nn、mm 和 kk(3≤n,m≤1093 \leq n,m \leq 10^9,1≤k≤1051 \leq k \leq 10^5)——分别表示图片的行数、列数以及颜料种类数。

下一行包含 kk 个整数 a1,a2,…,aka_1,a_2,\dots, a_k(1≤ai≤1091 \leq a_i \leq 10^9)——其中 aia_i 表示第 ii 种颜料最多可涂色的格子数。

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

输出格式

For each test case, print "Yes" (without quotes) if it is possible to color a beautiful picture. Otherwise, print "No" (without quotes).

对于每个测试用例,如果能够绘制出一幅美丽的图画,则输出“Yes”(不带引号);否则,输出“No”(不带引号)。

输入输出样例

  • 输入#1

    6
    4 6 3
    12 9 8
    3 3 2
    8 8
    3 3 2
    9 5
    4 5 2
    10 11
    5 4 2
    9 11
    10 10 3
    11 45 14

    输出#1

    Yes
    No
    Yes
    Yes
    No
    No

说明/提示

In the first test case, one possible solution is as follows:

In the third test case, we can color all cells with pigment 11.

在第一个测试用例中,一种可能的解法如下:

在第三个测试用例中,我们可以用颜料 11 给所有格子染色。

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

首页