102642: [AtCoder]ABC264 C - Matrix Reducing

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

You are given a matrix $A$ with $H_1$ rows and $W_1$ columns, and a matrix $B$ with $H_2$ rows and $W_2$ columns.

  • For all integer pairs $(i, j)$ such that $1 \leq i \leq H_1$ and $1 \leq j \leq W_1$, the element at the $i$-th row and $j$-th column of matrix $A$ is $A_{i, j}$.
  • For all integer pairs $(i, j)$ such that $1 \leq i \leq H_2$ and $1 \leq j \leq W_2$, the element at the $i$-th row and $j$-th column of matrix $B$ is $B_{i, j}$.

You may perform the following operations on the matrix $A$ any number of (possibly $0$) times in any order:

  • Choose an arbitrary row of $A$ and remove it.
  • Choose an arbitrary column of $A$ and remove it.

Determine if it is possible to make the matrix $A$ equal the matrix $B$.

Constraints

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

Input

Input is given from Standard Input in the following format:

$H_1$ $W_1$
$A_{1, 1}$ $A_{1, 2}$ $\ldots$ $A_{1, W_1}$
$A_{2, 1}$ $A_{2, 2}$ $\ldots$ $A_{2, W_1}$
$\vdots$
$A_{H_1, 1}$ $A_{H_1, 2}$ $\ldots$ $A_{H_1, W_1}$
$H_2$ $W_2$
$B_{1, 1}$ $B_{1, 2}$ $\ldots$ $B_{1, W_2}$
$B_{2, 1}$ $B_{2, 2}$ $\ldots$ $B_{2, W_2}$
$\vdots$
$B_{H_2, 1}$ $B_{H_2, 2}$ $\ldots$ $B_{H_2, W_2}$

Output

Print Yes if it is possible to make the matrix $A$ equal the matrix $B$; 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 $2$-nd column from the initial $A$ results in:

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

Then, removing the $3$-rd row from $A$ results in:

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

Then, removing the $1$-st row from $A$ results in:

6 8 9 10
16 18 19 20

Then, removing the $4$-th column from $A$ results in:

6 8 9
16 18 19

Now the matrix equals the matrix $B$.
Thus, we can make the matrix $A$ equal the matrix $B$ 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 $A$ equal the matrix $B$, so No should be printed.

Input

题意翻译

给定两个矩阵 $A,B$,长和宽分别为 $W_1,H_1,W_2,H_2$。 每一次操作可以删掉矩阵 $A$ 中的一行或一列,如果可以通过一些操作得到矩阵 $B$ 输出 $\mathtt{Yes}$,否则输出 $\mathtt{No}$。 $\mathtt{translate\ by\ Fire\_flame}$

Output

分数:300分 部分 问题说明 你得到了一个矩阵$A$,它有$H_1$行和$W_1$列,还有一个矩阵$B$,它有$H_2$行和$W_2$列。 * 对于所有的整数对$(i, j)$,满足$1 \leq i \leq H_1$和$1 \leq j \leq W_1$,矩阵$A$的第$i$行和第$j$列的元素为$A_{i, j}$。 * 对于所有的整数对$(i, j)$,满足$1 \leq i \leq H_2$和$1 \leq j \leq W_2$,矩阵$B$的第$i$行和第$j$列的元素为$B_{i, j}$。 你可以按任意顺序对矩阵$A$进行任意次数(可能是0次)的以下操作: * 选择$A$的任意一行并删除它。 * 选择$A$的任意一列并删除它。 确定是否可能使矩阵$A$等于矩阵$B$。 部分 约束 * $1 \leq H_2 \leq H_1 \leq 10$ * $1 \leq W_2 \leq W_1 \leq 10$ * $1 \leq A_{i, j} \leq 10^9$ * $1 \leq B_{i, j} \leq 10^9$ * 输入中的所有值都是整数。 部分 输入 输入格式如下: $H_1$ $W_1$ $A_{1, 1}$ $A_{1, 2}$ $\ldots$ $A_{1, W_1}$ $A_{2, 1}$ $A_{2, 2}$ $\ldots$ $A_{2, W_1}$ $\vdots$ $A_{H_1, 1}$ $A_{H_1, 2}$ $\ldots$ $A_{H_1, W_1}$ $H_2$ $W_2$ $B_{1, 1}$ $B_{1, 2}$ $\ldots$ $B_{1, W_2}$ $B_{2, 1}$ $B_{2, 2}$ $\ldots$ $B_{2, W_2}$ $\vdots$ $B_{H_2, 1}$ $B_{H_2, 2}$ $\ldots$ $B_{H_2, W_2}$ 部分 输出 如果可能使矩阵$A$等于矩阵$B$,则打印Yes;否则打印No。注意,裁判是区分大小写的。 部分 样例输入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 部分 样例输出1 Yes 从初始的$A$中删除第2列得到: 1 3 4 5 6 8 9 10 11 13 14 15 16 18 19 20 然后从$A$中删除第3行得到: 1 3 4 5 6 8 9 10 16 18 19 20 然后从$A$中删除第1行得到: 6 8 9 10 16 18 19 20 然后从$A$中删除第4列得到: 6 8 9 16 18 19 现在矩阵等于矩阵$B$。 因此,我们可以通过重复操作使矩阵$A$等于矩阵$B$,所以应打印Yes。 部分 样例输入2 3 3 1 1 1 1 1 1 1 1 1 1 1 2

加入题单

算法标签: