CF1579C.Ticks

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Casimir has a rectangular piece of paper with a checkered field of size n×mn \times m. Initially, all cells of the field are white.

Let us denote the cell with coordinates ii vertically and jj horizontally by (i,j)(i, j). The upper left cell will be referred to as (1,1)(1, 1) and the lower right cell as (n,m)(n, m).

Casimir draws ticks of different sizes on the field. A tick of size dd (d>0d \gt 0) with its center in cell (i,j)(i, j) is drawn as follows:

  1. First, the center cell (i,j)(i, j) is painted black.
  2. Then exactly dd cells on the top-left diagonally to the center and exactly dd cells on the top-right diagonally to the center are also painted black.
  3. That is all the cells with coordinates (i−h,j±h)(i - h, j \pm h) for all hh between 00 and dd are painted. In particular, a tick consists of 2d+12d + 1 black cells.

An already painted cell will remain black if painted again. Below you can find an example of the 4×94 \times 9 box, with two ticks of sizes 22 and 33.

You are given a description of a checkered field of size n×mn \times m. Casimir claims that this field came about after he drew some (possibly 00) ticks on it. The ticks could be of different sizes, but the size of each tick is at least kk (that is, d≥kd \ge k for all the ticks).

Determine whether this field can indeed be obtained by drawing some (possibly none) ticks of sizes d≥kd \ge k or not.

卡西米尔有一张 n×mn \times m 的方格纸。初始时,方格中所有单元格均为白色。

我们用 (i,j)(i, j) 表示第 ii 行(从上往下数)、第 jj 列(从左往右数)的单元格。左上角单元格记为 (1,1)(1, 1),右下角单元格记为 (n,m)(n, m)。

卡西米尔在方格纸上绘制不同尺寸的“勾号”(tick)。一个尺寸为 dd(d>0d > 0)且中心位于单元格 (i,j)(i, j) 的勾号按如下方式绘制:

  1. 首先,将中心单元格 (i,j)(i, j) 涂黑;
  2. 然后,恰好将中心单元格左上方对角线方向的 dd 个单元格、以及右上方对角线方向的 dd 个单元格也涂黑;
  3. 即:对所有满足 0≤h≤d0 \le h \le d 的整数 hh,将坐标为 (i−h,j±h)(i - h, j \pm h) 的所有单元格涂黑。特别地,一个尺寸为 dd 的勾号共包含 2d+12d + 1 个黑色单元格。

若某个单元格已被涂黑,则再次涂黑不会改变其颜色(即黑色保持不变)。下方是一个 4×94 \times 9 的方格示例,其中绘制了两个尺寸分别为 22 和 33 的勾号。

现给你一个 n×mn \times m 方格的描述(即每个单元格是黑还是白)。卡西米尔声称该方格是在他绘制了若干(可能为 00 个)勾号之后得到的。这些勾号可以具有不同尺寸,但每个勾号的尺寸至少为 kk(即所有勾号均满足 d≥kd \ge k)。

请判断:该方格是否确实可能通过绘制若干(可为零个)尺寸均不小于 kk 的勾号而得到。

输入格式

The first line contains an integer tt (1≤t≤1001 \leq t \leq 100) — the number test cases.

The following lines contain the descriptions of the test cases.

The first line of the test case description contains the integers nn, mm, and kk (1≤k≤n≤101 \le k \le n \le 10; 1≤m≤191 \le m \le 19) — the field size and the minimum size of the ticks that Casimir drew. The following nn lines describe the field: each line consists of mm characters either being '.' if the corresponding cell is not yet painted or '*' otherwise.

第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100)—— 表示测试用例的数量。

接下来的若干行包含各测试用例的描述。

每个测试用例的第一行包含三个整数 nn、mm 和 kk(1≤k≤n≤101 \leq k \leq n \leq 10;1≤m≤191 \leq m \leq 19)—— 分别表示方格区域的尺寸以及卡西米尔所画刻度的最小尺寸。接下来的 nn 行描述该方格区域:每行由 mm 个字符组成,其中 '.' 表示对应单元格尚未被涂色,'*' 表示已被涂色。

输出格式

Print tt lines, each line containing the answer to the corresponding test case. The answer to a test case should be YES if the given field can be obtained by drawing ticks of at least the given size and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answers).

输出 tt 行,每行包含对应测试用例的答案。若给定的方格图可通过绘制至少指定大小的“tick”(勾号)得到,则答案为 YES;否则为 NO。

您可以以任意大小写形式输出每个字母(例如,字符串 yEs、yes、Yes 和 YES 均被视为肯定回答)。

输入输出样例

  • 输入#1

    8
    2 3 1
    *.*
    ...
    4 9 2
    *.*.*...*
    .*.*...*.
    ..*.*.*..
    .....*...
    4 4 1
    *.*.
    ****
    .**.
    ....
    5 5 1
    .....
    *...*
    .*.*.
    ..*.*
    ...*.
    5 5 2
    .....
    *...*
    .*.*.
    ..*.*
    ...*.
    4 7 1
    *.....*
    .....*.
    ..*.*..
    ...*...
    3 3 1
    ***
    ***
    ***
    3 5 1
    *...*
    .***.
    .**..

    输出#1

    NO
    YES
    YES
    YES
    NO
    NO
    NO
    NO

说明/提示

The first sample test case consists of two asterisks neither of which can be independent ticks since ticks of size 00 don't exist.

The second sample test case is already described in the statement (check the picture in the statement). This field can be obtained by drawing ticks of sizes 22 and 33, as shown in the figure.

The field in the third sample test case corresponds to three ticks of size 11. Their center cells are marked with blue\color{blue}{\text{blue}}, red\color{red}{\text{red}} and green\color{green}{\text{green}} colors:

*.*.

**\color{blue}{\textbf{*}}**

.**\color{green}{\textbf{*}}\color{red}{\textbf{*}}.

....

The field in the fourth sample test case could have been obtained by drawing two ticks of sizes 11 and 22. Their vertices are marked below with blue\color{blue}{\text{blue}} and red\color{red}{\text{red}} colors respectively:

.....

*...*

.*.*.

..*\color{red}{\textbf{*}}.*

...*\color{blue}{\textbf{*}}.

The field in the fifth sample test case can not be obtained because k=2k = 2, and the last asterisk in the fourth row from the top with coordinates (4,5)(4, 5) can only be a part of a tick of size 11.

The field in the sixth sample test case can not be obtained because the top left asterisk (1,1)(1, 1) can't be an independent tick, since the sizes of the ticks must be positive, and cannot be part of a tick with the center cell in the last row, since it is separated from it by a gap (a point, '.') in (2,2)(2, 2).

In the seventh sample test case, similarly, the field can not be obtained by the described process because the asterisks with coordinates (1,2)(1, 2) (second cell in the first row), (3,1)(3, 1) and (3,3)(3, 3) (leftmost and rightmost cells in the bottom) can not be parts of any ticks.

第一个样例测试用例包含两个星号(*),但它们均不能作为独立的“刻度”(tick),因为尺寸为 00 的刻度不存在。

第二个样例测试用例已在题目描述中给出(请参见题目描述中的图片)。该网格可通过绘制尺寸分别为 22 和 33 的两个刻度得到,如图所示。

第三个样例测试用例对应的网格由三个尺寸均为 11 的刻度构成。它们的中心格子分别用 蓝色\color{blue}{\text{蓝色}}、红色\color{red}{\text{红色}} 和 绿色\color{green}{\text{绿色}} 标出:

*.*.

**\color{blue}{\textbf{*}}**

.**\color{green}{\textbf{*}}\color{red}{\textbf{*}}.

....

第四个样例测试用例对应的网格可能由两个尺寸分别为 11 和 22 的刻度绘制而成。它们的顶点(即中心格子)分别用 蓝色\color{blue}{\text{蓝色}} 和 红色\color{red}{\text{红色}} 标出如下:

.....

*...*

.*.*.

..*\color{red}{\textbf{*}}.*

...*\color{blue}{\textbf{*}}.

第五个样例测试用例对应的网格无法通过该过程生成,因为 k=2k = 2,而从上往下数第四行中坐标为 (4,5)(4, 5) 的最后一个星号只能属于一个尺寸为 11 的刻度。

第六个样例测试用例对应的网格无法生成,因为左上角的星号 (1,1)(1, 1) 既不能作为独立刻度(因刻度尺寸必须为正整数),也不能属于以最后一行某格为中心的刻度——因为其与该潜在中心格之间在位置 (2,2)(2, 2) 处存在一个空隙(即一个点 .)。

在第七个样例测试用例中,该网格同样无法通过所述过程生成,因为坐标为 (1,2)(1, 2)(第一行第二个格子)、(3,1)(3, 1) 和 (3,3)(3, 3)(最底行最左与最右的格子)的星号无法成为任何刻度的一部分。

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

首页