103072: [Atcoder]ABC307 C - Ideal Sheet
Description
Score : $300$ points
Problem Statement
Takahashi has two sheets $A$ and $B$, each composed of black squares and transparent squares, and an infinitely large sheet $C$ composed of transparent squares.
There is also an ideal sheet $X$ for Takahashi composed of black squares and transparent squares.
The sizes of sheets $A$, $B$, and $X$ are $H_A$ rows $\times$ $W_A$ columns, $H_B$ rows $\times$ $W_B$ columns, and $H_X$ rows $\times$ $W_X$ columns, respectively.
The squares of sheet $A$ are represented by $H_A$ strings of length $W_A$, $A_1, A_2, \ldots, A_{H_A}$ consisting of .
and #
.
If the $j$-th character $(1\leq j\leq W_A)$ of $A_i$ $(1\leq i\leq H_A)$ is .
, the square at the $i$-th row from the top and $j$-th column from the left is transparent; if it is #
, that square is black.
Similarly, the squares of sheets $B$ and $X$ are represented by $H_B$ strings of length $W_B$, $B_1, B_2, \ldots, B_{H_B}$, and $H_X$ strings of length $W_X$, $X_1, X_2, \ldots, X_{H_X}$, respectively.
Takahashi's goal is to create sheet $X$ using all black squares in sheets $A$ and $B$ by following the steps below with sheets $A$, $B$, and $C$.
- Paste sheets $A$ and $B$ onto sheet $C$ along the grid. Each sheet can be pasted anywhere by translating it, but it cannot be cut or rotated.
- Cut out an $H_X\times W_X$ area from sheet $C$ along the grid. Here, a square of the cut-out sheet will be black if a black square of sheet $A$ or $B$ 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 $A$ and $B$. The black squares of sheets $A$ and $B$ may overlap on the cut-out sheet.
- The cut-out sheet coincides sheet $X$ without rotating or flipping.
Constraints
- $1\leq H_A, W_A, H_B, W_B, H_X, W_X\leq 10$
- $H_A, W_A, H_B, W_B, H_X, W_X$ are integers.
- $A_i$ is a string of length $W_A$ consisting of
.
and#
. - $B_i$ is a string of length $W_B$ consisting of
.
and#
. - $X_i$ is a string of length $W_X$ consisting of
.
and#
. - Sheets $A$, $B$, and $X$ each contain at least one black square.
Input
The input is given from Standard Input in the following format:
$H_A$ $W_A$ $A_1$ $A_2$ $\vdots$ $A_{H_A}$ $H_B$ $W_B$ $B_1$ $B_2$ $\vdots$ $B_{H_B}$ $H_X$ $W_X$ $X_1$ $X_2$ $\vdots$ $X_{H_X}$
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 $A$ onto sheet $C$, as shown in the figure below.
$\vdots$ ....... .#.#... $\cdots$.......$\cdots$ ..#.... ....... $\vdots$
Next, paste sheet $B$ so that its top-left corner aligns with that of sheet $A$, as shown in the figure below.
$\vdots$ ....... .#.#... $\cdots$..#....$\cdots$ ..#.... ....... $\vdots$
Now, cut out a $5\times 3$ 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 $A$ and $B$ and matches sheet $X$, satisfying the conditions.
Therefore, print Yes
.
Sample Input 2
2 2 #. .# 2 2 #. .# 2 2 ## ##
Sample Output 2
No
Note that sheets $A$ and $B$ 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 $B$, so you cannot satisfy the first condition.
Therefore, print No
.
Sample Input 4
3 3 ### ... ... 3 3 #.. #.. #.. 3 3 ..# ..# ###
Sample Output 4
Yes
Input
题意翻译
### 题目描述 高桥有两张由方格组成的薄片,每个方格可能是透明的或黑色的。第一张的高 $H_A$ 宽 $W_A$ 个格子, 第二张高 $H_B$ 宽 $W_B$ 个格子。现在高桥将它们通过平移重叠在一起(不能旋转翻转),相对位置任意,想要得到图形 $X$ (高宽$H_X$,$W_X$),请输出是否可能。用`.`表示透明格子,`#`表示黑色格子。 ### 输入格式 第一行两个整数 $H_A$ , $W_A$ 接下来 $H_A$ 行字符,表示薄片 $A$。 同理输入薄片 $B$ , $X$。 ### 输出格式 一行,`Yes`表示可能,`No`表示不可能得到 $X$。 ### 数据范围 $1\leq$ 所有薄片高、宽 $\leq 10$ ### 样例解释 Sample Explanation $2$ 不能旋转薄片,因此不能得到 $X$ 。Output
得分:300分
问题描述
高桥持有两张由黑色正方形和透明正方形组成的纸张$A$和$B$,以及一张由无限数量的透明正方形组成的纸张$C$。
还有一张理想的纸张$X$,由黑色正方形和透明正方形组成。
纸张$A$、$B$和$X$的大小分别为$H_A$行$\times$ $W_A$列、$H_B$行$\times$ $W_B$列和$H_X$行$\times$ $W_X$列。
纸张$A$的正方形由$H_A$个长度为$W_A$的字符串$A_1, A_2, \ldots, A_{H_A}$表示,由.
和#
组成。如果$A_i$ $(1\leq i\leq H_A)$的第$j$个字符$(1\leq j\leq W_A)$为.
,则纸张$A$从顶部数第$i$行、从左数第$j$列的正方形为透明;如果为#
,则该正方形为黑色。纸张$B$和$X$的正方形分别由$H_B$个长度为$W_B$的字符串$B_1, B_2, \ldots, B_{H_B}$和$H_X$个长度为$W_X$的字符串$X_1, X_2, \ldots, X_{H_X}$表示。
高桥的目标是通过以下步骤使用纸张$A$、$B$和$C$创建纸张$X$。
- 沿着网格将纸张$A$和$B$粘贴到纸张$C$上。每张纸张可以通过平移粘贴到任何位置,但不能被切割或旋转。
- 沿着网格从纸张$C$上切出一个$H_X\times W_X$的区域。在这里,剪下的纸张上的一个正方形如果粘贴了纸张$A$或$B$的黑色正方形,则为黑色;否则为透明。
通过适当选择粘贴纸张的位置和切出的区域,确定高桥是否可以实现他的目标,即他是否可以满足以下两个条件。
- 剪下的纸张包括纸张$A$和$B$的所有黑色正方形。纸张$A$和$B$的黑色正方形可以在剪下的纸张上重叠。
- 剪下的纸张与纸张$X$完全重合,不旋转或翻转。
约束条件
- $1\leq H_A, W_A, H_B, W_B, H_X, W_X\leq 10$
- $H_A, W_A, H_B, W_B, H_X, W_X$为整数。
- $A_i$为长度为$W_A$的字符串,由
.
和#
组成。 - $B_i$为长度为$W_B$的字符串,由
.
和#
组成。 - $X_i$为长度为$W_X$的字符串,由
.
和#
组成。 - 纸张$A$、$B$和$X$各自至少包含一个黑色正方形。
输入
输入从标准输入中按以下格式给出:
$H_A$ $W_A$ $A_1$ $A_2$ $\vdots$ $A_{H_A}$ $H_B$ $W_B$ $B_1$ $B_2$ $\vdots$ $B_{H_B}$ $H_X$ $W_X$ $X_1$ $X_2$ $\vdots$ $X_{H_X}$
输出
如果高桥可以实现问题描述中的目标,则输出Yes
;否则,输出No
。
样例输入1
3 5 #.#.. ..... .#... 2 2 #. .# 5 3 ... #.# .#. .#. ...
样例输出1
Yes
首先,按照下图所示的方式将纸张$A$粘贴到纸张$C$上。
$\vdots$ ....... .#.#... $\cdots$.......$\cdots$ ..#.... ....... $\vdots$
接下来,将纸张$B$粘贴到纸张$A$的左上角对齐的位置,如图所示。
$\vdots$ ....... .#.#... $\cdots$..#....$\cdots$ ..#.... ....... $\vdots$
现在,从范围上方第一行和第二列的正方形作为左上角切出一个$5\times 3$的区域,如图所示。
... #.# .#. .#. ...
这包括了纸张$A$和$B$的所有黑色正方形,并与纸张$X$相匹配,满足条件。
因此,输出Yes
。
样例输入2
2 2 #. .# 2 2 #. .# 2 2 ## ##
样例输出2
No
注意粘贴纸张$A$和$B$时,不能旋转或翻转它们。
样例输入3
1 1 # 1 2 ## 1 1 #
样例输出3
No
无论如何粘贴或切割,都无法切出一张包含纸张$B$所有黑色正方形的纸张,因此无法满足第一个条件。因此,输出No
。
样例输入4
3 3 ### ... ... 3 3 #.. #.. #.. 3 3 ..# ..# ###
样例输出4
Yes