#abc264c. C - Matrix Reducing

C - Matrix Reducing

Score : 300300 points

问题陈述

给定两个矩阵:矩阵 AA 具有 H1H_1 行和 W1W_1 列,矩阵 BB 具有 H2H_2 行和 W2W_2 列。

  • 对于所有满足条件 1iH11 \leq i \leq H_11jW11 \leq j \leq W_1 的整数对 (i,j)(i, j),矩阵 AA 中第 ii 行第 jj 列的元素记为 Ai,jA_{i, j}
  • 对于所有满足条件 1iH21 \leq i \leq H_21jW21 \leq j \leq W_2 的整数对 (i,j)(i, j),矩阵 BB 中第 ii 行第 jj 列的元素记为 Bi,jB_{i, j}

你可以对矩阵 AA 进行任意次数(包括可能的 00 次)以下操作,且顺序不限:

  • 选择矩阵 AA 中的任意一行并移除它。
  • 选择矩阵 AA 中的任意一列并移除它。

确定是否可以通过上述操作使矩阵 AA 等于矩阵 BB

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

Problem Statement

You are given a matrix AA with H1H_1 rows and W1W_1 columns, and a matrix BB with H2H_2 rows and W2W_2 columns.

  • For all integer pairs (i,j)(i, j) such that 1iH11 \leq i \leq H_1 and 1jW11 \leq j \leq W_1, the element at the ii-th row and jj-th column of matrix AA is Ai,jA_{i, j}.
  • For all integer pairs (i,j)(i, j) such that 1iH21 \leq i \leq H_2 and 1jW21 \leq j \leq W_2, the element at the ii-th row and jj-th column of matrix BB is Bi,jB_{i, j}.

You may perform the following operations on the matrix AA any number of (possibly 00) times in any order:

  • Choose an arbitrary row of AA and remove it.
  • Choose an arbitrary column of AA and remove it.

Determine if it is possible to make the matrix AA equal the matrix BB.

Constraints

  • 1H2H1101 \leq H_2 \leq H_1 \leq 10
  • 1W2W1101 \leq W_2 \leq W_1 \leq 10
  • 1Ai,j1091 \leq A_{i, j} \leq 10^9
  • 1Bi,j1091 \leq B_{i, j} \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

H1H_1 W1W_1

A1,1A_{1, 1} A1,2A_{1, 2} \ldots A1,W1A_{1, W_1}

A2,1A_{2, 1} A2,2A_{2, 2} \ldots A2,W1A_{2, W_1}

\vdots

AH1,1A_{H_1, 1} AH1,2A_{H_1, 2} \ldots AH1,W1A_{H_1, W_1}

H2H_2 W2W_2

B1,1B_{1, 1} B1,2B_{1, 2} \ldots B1,W2B_{1, W_2}

B2,1B_{2, 1} B2,2B_{2, 2} \ldots B2,W2B_{2, W_2}

\vdots

BH2,1B_{H_2, 1} BH2,2B_{H_2, 2} \ldots BH2,W2B_{H_2, W_2}

Output

Print Yes if it is possible to make the matrix AA equal the matrix BB; print No otherwise. Note that the judge is case-sensitive.

Sample Input 1

4 5
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
2 3
6 8 9
16 18 19

Sample Output 1

Yes

Removing the 22-nd column from the initial AA results in:

1 3 4 5
6 8 9 10
11 13 14 15
16 18 19 20

Then, removing the 33-rd row from AA results in:

1 3 4 5
6 8 9 10
16 18 19 20

Then, removing the 11-st row from AA results in:

6 8 9 10
16 18 19 20

Then, removing the 44-th column from AA results in:

6 8 9
16 18 19

Now the matrix equals the matrix BB. Thus, we can make the matrix AA equal the matrix BB by repeating the operations, so Yes should be printed.

Sample Input 2

3 3
1 1 1
1 1 1
1 1 1
1 1
2

Sample Output 2

No

Regardless of how we perform the operations, we cannot make the matrix AA equal the matrix BB, so No should be printed.

update @ 2024/3/10 11:09:15