1579C.md (4649B)
1 Source: https://codeforces.com/problemset/problem/1579/C 2 3 C. Ticks 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Casimir has a rectangular piece of paper with a checkered field of size $n \times m$. Initially, all cells of the field are white. 22 23 Let us denote the cell with coordinates $i$ vertically and $j$ horizontally by $(i, j)$. The upper left cell will be referred to as $(1, 1)$ and the lower right cell as $(n, m)$. 24 25 Casimir draws ticks of different sizes on the field. A tick of size $d$ ($d \gt 0$) with its center in cell $(i, j)$ is drawn as follows: 26 27 1. First, the center cell $(i, j)$ is painted black. 28 2. Then exactly $d$ cells on the top-left diagonally to the center and exactly $d$ cells on the top-right diagonally to the center are also painted black. 29 3. That is all the cells with coordinates $(i - h, j \pm h)$ for all $h$ between $0$ and $d$ are painted. In particular, a tick consists of $2d + 1$ black cells. 30 31 An already painted cell will remain black if painted again. Below you can find an example of the $4 \times 9$ box, with two ticks of sizes $2$ and $3$. 32 33  34 35 You are given a description of a checkered field of size $n \times m$. Casimir claims that this field came about after he drew some (possibly $0$) ticks on it. The ticks could be of different sizes, but the size of each tick is at least $k$ (that is, $d \ge k$ for all the ticks). 36 37 Determine whether this field can indeed be obtained by drawing some (possibly none) ticks of sizes $d \ge k$ or not. 38 39 Input 40 41 The first line contains an integer $t$ ($1 \leq t \leq 100$) — the number test cases. 42 43 The following lines contain the descriptions of the test cases. 44 45 The first line of the test case description contains the integers $n$, $m$, and $k$ ($1 \le k \le n \le 10$; $1 \le m \le 19$) — the field size and the minimum size of the ticks that Casimir drew. The following $n$ lines describe the field: each line consists of $m$ characters either being '.' if the corresponding cell is not yet painted or '*' otherwise. 46 47 Output 48 49 Print $t$ 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. 50 51 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). 52 53 Example 54 55 Input 56 57 ``` 58 8 59 2 3 1 60 *.* 61 ... 62 4 9 2 63 *.*.*...* 64 .*.*...*. 65 ..*.*.*.. 66 .....*... 67 4 4 1 68 *.*. 69 **** 70 .**. 71 .... 72 5 5 1 73 ..... 74 *...* 75 .*.*. 76 ..*.* 77 ...*. 78 5 5 2 79 ..... 80 *...* 81 .*.*. 82 ..*.* 83 ...*. 84 4 7 1 85 *.....* 86 .....*. 87 ..*.*.. 88 ...*... 89 3 3 1 90 *** 91 *** 92 *** 93 3 5 1 94 *...* 95 .***. 96 .**.. 97 ``` 98 99 Output 100 101 ``` 102 NO 103 YES 104 YES 105 YES 106 NO 107 NO 108 NO 109 NO 110 ``` 111 112 Note 113 114 The first sample test case consists of two asterisks neither of which can be independent ticks since ticks of size $0$ don't exist. 115 116 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 $2$ and $3$, as shown in the figure. 117 118 The field in the third sample test case corresponds to three ticks of size $1$. Their center cells are marked with $\color{blue}{\text{blue}}$, $\color{red}{\text{red}}$ and $\color{green}{\text{green}}$ colors: 119 120 | | 121 | --- | 122 | *.*. | 123 | *$\color{blue}{\textbf{*}}$** | 124 | .$\color{green}{\textbf{*}}\color{red}{\textbf{*}}$. | 125 | .... | 126 127 The field in the fourth sample test case could have been obtained by drawing two ticks of sizes $1$ and $2$. Their vertices are marked below with $\color{blue}{\text{blue}}$ and $\color{red}{\text{red}}$ colors respectively: 128 129 | | 130 | --- | 131 | ..... | 132 | *...* | 133 | .*.*. | 134 | ..$\color{red}{\textbf{*}}$.* | 135 | ...$\color{blue}{\textbf{*}}$. | 136 137 The field in the fifth sample test case can not be obtained because $k = 2$, and the last asterisk in the fourth row from the top with coordinates $(4, 5)$ can only be a part of a tick of size $1$. 138 139 The field in the sixth sample test case can not be obtained because the top left asterisk $(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)$. 140 141 In the seventh sample test case, similarly, the field can not be obtained by the described process because the asterisks with coordinates $(1, 2)$ (second cell in the first row), $(3, 1)$ and $(3, 3)$ (leftmost and rightmost cells in the bottom) can not be parts of any ticks.