#abc307c. C - Ideal Sheet
C - Ideal Sheet
Score : points
问题描述
Takahashi 拥有两张由黑色正方形和透明正方形组成的纸张 和 ,以及一张无限大的、由透明正方形组成的纸张 。 此外,他还有一张理想的参照纸张 ,同样由黑色正方形和透明正方形组成。
纸张 、 和 的尺寸分别为 行 列, 行 列,以及 行 列。
纸张 上的正方形由 个长度为 的字符串表示,分别为 ,包含字符 .
和 #
。
如果 ()的第 个字符 是 .
, 那么从上到下第 行、从左到右第 列的正方形是透明的;如果是 #
,则该正方形为黑色。
类似地,纸张 和 上的正方形分别由 个长度为 的字符串 和 个长度为 的字符串 表示。
Takahashi 的目标是通过以下步骤使用纸张 和 中的所有黑色正方形来制作出纸张 ,操作对象包括纸张 、 和 。
- 将纸张 和 沿网格贴在纸张 上。每张纸可以通过平移贴在任何位置,但不能裁剪或旋转。
- 沿着网格从纸张 上裁剪出一个 的区域。这里的裁剪部分,如果贴有纸张 或 的黑色正方形,则为黑色;否则为透明。
判断 Takahashi 是否能通过合理选择纸张的粘贴位置及裁剪区域来实现他的目标,即他是否能让以下两个条件同时满足:
- 裁剪出的纸张中包含了纸张 和 的所有黑色正方形。纸张 和 的黑色正方形在裁剪纸上可能重叠。
- 裁剪出的纸张在不旋转或翻转的情况下与纸张 完全一致。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi has two sheets and , each composed of black squares and transparent squares, and an infinitely large sheet composed of transparent squares. There is also an ideal sheet for Takahashi composed of black squares and transparent squares.
The sizes of sheets , , and are rows columns, rows columns, and rows columns, respectively.
The squares of sheet are represented by strings of length , consisting of .
and #
.
If the -th character of is .
, the square at the -th row from the top and -th column from the left is transparent; if it is #
, that square is black.
Similarly, the squares of sheets and are represented by strings of length , , and strings of length , , respectively.
Takahashi's goal is to create sheet using all black squares in sheets and by following the steps below with sheets , , and .
- Paste sheets and onto sheet along the grid. Each sheet can be pasted anywhere by translating it, but it cannot be cut or rotated.
- Cut out an area from sheet along the grid. Here, a square of the cut-out sheet will be black if a black square of sheet or is pasted there, and transparent otherwise.
Determine whether Takahashi can achieve his goal by appropriately choosing the positions where the sheets are pasted and the area to cut out, that is, whether he can satisfy both of the following conditions.
- The cut-out sheet includes all black squares of sheets and . The black squares of sheets and may overlap on the cut-out sheet.
- The cut-out sheet coincides sheet without rotating or flipping.
Constraints
- are integers.
- is a string of length consisting of
.
and#
. - is a string of length consisting of
.
and#
. - is a string of length consisting of
.
and#
. - Sheets , , and each contain at least one black square.
Input
The input is given from Standard Input in the following format:
Output
If Takahashi can achieve the goal described in the problem statement, print Yes
; otherwise, print No
.
Sample Input 1
3 5
#.#..
.....
.#...
2 2
#.
.#
5 3
...
#.#
.#.
.#.
...
Sample Output 1
Yes
First, paste sheet onto sheet , as shown in the figure below.
.......
.#.#...
.......
..#....
.......
Next, paste sheet so that its top-left corner aligns with that of sheet , as shown in the figure below.
.......
.#.#...
..#....
..#....
.......
Now, cut out a area with the square in the first row and second column of the range illustrated above as the top-left corner, as shown in the figure below.
...
#.#
.#.
.#.
...
This includes all black squares of sheets and and matches sheet , satisfying the conditions.
Therefore, print Yes
.
Sample Input 2
2 2
#.
.#
2 2
#.
.#
2 2
##
##
Sample Output 2
No
Note that sheets and may not be rotated or flipped when pasting them.
Sample Input 3
1 1
#
1 2
##
1 1
#
Sample Output 3
No
No matter how you paste or cut, you cannot cut out a sheet that includes all black squares of sheet , so you cannot satisfy the first condition. Therefore, print No
.
Sample Input 4
3 3
###
...
...
3 3
#..
#..
#..
3 3
..#
..#
###
Sample Output 4
Yes
update @ 2024/3/10 08:41:26