#abc307c. C - Ideal Sheet

C - Ideal Sheet

Score : 300300 points

问题描述

Takahashi 拥有两张由黑色正方形和透明正方形组成的纸张 AABB,以及一张无限大的、由透明正方形组成的纸张 CC。 此外,他还有一张理想的参照纸张 XX,同样由黑色正方形和透明正方形组成。

纸张 AABBXX 的尺寸分别为 HAH_A×\times WAW_A 列,HBH_B×\times WBW_B 列,以及 HXH_X×\times WXW_X 列。 纸张 AA 上的正方形由 HAH_A 个长度为 WAW_A 的字符串表示,分别为 A1,A2,,AHAA_1, A_2, \ldots, A_{H_A},包含字符 .#。 如果 AiA_i1iHA1\leq i\leq H_A)的第 jj 个字符 (1jWA)(1\leq j\leq W_A)., 那么从上到下第 ii 行、从左到右第 jj 列的正方形是透明的;如果是 #,则该正方形为黑色。 类似地,纸张 BBXX 上的正方形分别由 HBH_B 个长度为 WBW_B 的字符串 B1,B2,,BHBB_1, B_2, \ldots, B_{H_B}HXH_X 个长度为 WXW_X 的字符串 X1,X2,,XHXX_1, X_2, \ldots, X_{H_X} 表示。

Takahashi 的目标是通过以下步骤使用纸张 AABB 中的所有黑色正方形来制作出纸张 XX,操作对象包括纸张 AABBCC

  1. 将纸张 AABB 沿网格贴在纸张 CC 上。每张纸可以通过平移贴在任何位置,但不能裁剪或旋转。
  2. 沿着网格从纸张 CC 上裁剪出一个 HX×WXH_X\times W_X 的区域。这里的裁剪部分,如果贴有纸张 AABB 的黑色正方形,则为黑色;否则为透明。

判断 Takahashi 是否能通过合理选择纸张的粘贴位置及裁剪区域来实现他的目标,即他是否能让以下两个条件同时满足:

  • 裁剪出的纸张中包含了纸张 AABB所有黑色正方形。纸张 AABB 的黑色正方形在裁剪纸上可能重叠。
  • 裁剪出的纸张在不旋转或翻转的情况下与纸张 XX 完全一致。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi has two sheets AA and BB, each composed of black squares and transparent squares, and an infinitely large sheet CC composed of transparent squares. There is also an ideal sheet XX for Takahashi composed of black squares and transparent squares.

The sizes of sheets AA, BB, and XX are HAH_A rows ×\times WAW_A columns, HBH_B rows ×\times WBW_B columns, and HXH_X rows ×\times WXW_X columns, respectively. The squares of sheet AA are represented by HAH_A strings of length WAW_A, A1,A2,,AHAA_1, A_2, \ldots, A_{H_A} consisting of . and #. If the jj-th character (1jWA)(1\leq j\leq W_A) of AiA_i (1iHA)(1\leq i\leq H_A) is ., the square at the ii-th row from the top and jj-th column from the left is transparent; if it is #, that square is black. Similarly, the squares of sheets BB and XX are represented by HBH_B strings of length WBW_B, B1,B2,,BHBB_1, B_2, \ldots, B_{H_B}, and HXH_X strings of length WXW_X, X1,X2,,XHXX_1, X_2, \ldots, X_{H_X}, respectively.

Takahashi's goal is to create sheet XX using all black squares in sheets AA and BB by following the steps below with sheets AA, BB, and CC.

  1. Paste sheets AA and BB onto sheet CC along the grid. Each sheet can be pasted anywhere by translating it, but it cannot be cut or rotated.
  2. Cut out an HX×WXH_X\times W_X area from sheet CC along the grid. Here, a square of the cut-out sheet will be black if a black square of sheet AA or BB 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 AA and BB. The black squares of sheets AA and BB may overlap on the cut-out sheet.
  • The cut-out sheet coincides sheet XX without rotating or flipping.

Constraints

  • 1HA,WA,HB,WB,HX,WX101\leq H_A, W_A, H_B, W_B, H_X, W_X\leq 10
  • HA,WA,HB,WB,HX,WXH_A, W_A, H_B, W_B, H_X, W_X are integers.
  • AiA_i is a string of length WAW_A consisting of . and #.
  • BiB_i is a string of length WBW_B consisting of . and #.
  • XiX_i is a string of length WXW_X consisting of . and #.
  • Sheets AA, BB, and XX each contain at least one black square.

Input

The input is given from Standard Input in the following format:

HAH_A WAW_A

A1A_1

A2A_2

\vdots

AHAA_{H_A}

HBH_B WBW_B

B1B_1

B2B_2

\vdots

BHBB_{H_B}

HXH_X WXW_X

X1X_1

X2X_2

\vdots

XHXX_{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 AA onto sheet CC, as shown in the figure below.

\vdots

.......

.#.#...

\cdots.......\cdots

..#....

.......

\vdots

Next, paste sheet BB so that its top-left corner aligns with that of sheet AA, as shown in the figure below.

\vdots

.......

.#.#...

\cdots..#....\cdots

..#....

.......

\vdots

Now, cut out a 5×35\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 AA and BB and matches sheet XX, satisfying the conditions.

Therefore, print Yes.

Sample Input 2

2 2
#.
.#
2 2
#.
.#
2 2
##
##

Sample Output 2

No

Note that sheets AA and BB 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 BB, 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