#P14687. [ICPC 2025 Yokohama R] U-Shaped Panels

[ICPC 2025 Yokohama R] U-Shaped Panels

题目描述

A rectangular pond is in the backyard of your house. As the length and width of the pond are integer multiples of one meter, the pond can be considered to consist of one-meter-square sections.

You always feel the pond is too large, and you want to cover some of its sections using the panels kept in the barn. All of these panels have the same size and the same shape, consisting of one-meter-square boards arranged in a U shape. The overall size of the panels is kk meters by kk meters, and 3k23k - 2 boards are on the three edges of that square. The rest, the (k2)×(k1)(k - 2) \times (k - 1) rectangular area, is void. Figure H.1 illustrates a panel of size k=5k = 5.

:::align{center}

Figure H.1. A panel of size k=5k = 5 (left) and its top view (right) :::

You plan to cover certain one-meter-square sections of the pond with the panels and leave the rest uncovered. Panels should be placed so that each of their boards fits exactly one section. As long as this is satisfied, orientations of the panels can be arbitrarily chosen. Panels should not overlap one another nor stick out of the pond.

Determine whether your plan is feasible or not.

输入格式

The input contains one or more test cases. The first line of the input contains an integer tt (1t101 \le t \le 10), which is the number of test cases. The descriptions of the tt test cases follow, each in the following format.

n m kn\ m\ k s1s_1 \vdots sns_n

The first line contains three integers nn, mm, and kk. The integers nn and mm denote the length and the width of the pond, respectively (5n10005 \le n \le 1000, 5m10005 \le m \le 1000). The integer kk denotes the size of the U-shaped panels (5k10005 \le k \le 1000). The following nn lines represent your plan. The ii-th of them contains a string sis_i of length mm consisting of the characters '#' and '.'. Let us say a one-meter-square section is at (r,c)(r, c) if it lies between r1r - 1 meters and rr meters from the front edge, and between c1c - 1 meters and cc meters from the left edge. For each ii and jj, if the jj-th character of sis_i is '#', the section at (i,j)(i, j) should be fully covered with a board of a panel. Otherwise, the section should remain fully uncovered.

The sum of nn's over all the test cases does not exceed 1000. The same applies to mm.

输出格式

For each test case, output in a line yes if your plan is feasible; no otherwise.

1
10 10 5
..........
..........
....#####.
..#.#.#.#.
..#.#.#.#.
..#.#.#.#.
..#.#.#.#.
..#####...
..........
..........
yes
2
5 21 5
.#...##...###....##..
.#..#..#..#..#..#..#.
.#..#.....###...#....
.#..#..#..#.....#..#.
.#...##...#......##..
6 14 6
.############.
.#..........#.
.#..........#.
.#..........#.
.#..........#.
.############.
no
yes