#abc224b. B - Mongeness

B - Mongeness

Score : 200200 points

问题描述

我们有一个由 HH 行(水平)和 WW 列(垂直)构成的网格,其中每个格子包含一个整数。位于从上到下的第 ii 行、从左到右的第 jj 列的格子上的整数为 Ai,jA_{i, j}

确定该网格是否满足以下条件:

对于所有满足 1i1<i2H1 \leq i_1 < i_2 \leq H1j1<j2W1 \leq j_1 < j_2 \leq W 的整数四元组 (i1,i2,j1,j2)(i_1, i_2, j_1, j_2),均有 $A_{i_1, j_1} + A_{i_2, j_2} \leq A_{i_2, j_1} + A_{i_1, j_2}$ 成立。

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

Problem Statement

We have a grid with HH horizontal rows and WW vertical columns, where each square contains an integer. The integer written on the square at the ii-th row from the top and jj-th column from the left is Ai,jA_{i, j}.

Determine whether the grid satisfies the condition below.

$A_{i_1, j_1} + A_{i_2, j_2} \leq A_{i_2, j_1} + A_{i_1, j_2}$ holds for every quadruple of integers (i1,i2,j1,j2)(i_1, i_2, j_1, j_2) such that 1i1<i2H1 \leq i_1 < i_2 \leq H and 1j1<j2W1 \leq j_1 < j_2 \leq W.

Constraints

  • 2H,W502 \leq H, W \leq 50
  • 1Ai,j1091 \leq A_{i, j} \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

HH WW

A1,1A_{1, 1} A1,2A_{1, 2} \cdots A1,WA_{1, W}

A2,1A_{2, 1} A2,2A_{2, 2} \cdots A2,WA_{2, W}

\vdots

AH,1A_{H, 1} AH,2A_{H, 2} \cdots AH,WA_{H, W}

Output

If the grid satisfies the condition in the Problem Statement, print Yes; otherwise, print No.

Sample Input 1

3 3
2 1 4
3 1 3
6 4 1

Sample Output 1

Yes

There are nine quadruples of integers (i1,i2,j1,j2)(i_1, i_2, j_1, j_2) such that 1i1<i2H1 \leq i_1 < i_2 \leq H and 1j1<j2W1 \leq j_1 < j_2 \leq W. For all of them, $A_{i_1, j_1} + A_{i_2, j_2} \leq A_{i_2, j_1} + A_{i_1, j_2}$ holds. Some examples follow.

  • For (i1,i2,j1,j2)=(1,2,1,2)(i_1, i_2, j_1, j_2) = (1, 2, 1, 2), we have $A_{i_1, j_1} + A_{i_2, j_2} = 2 + 1 \leq 3 + 1 = A_{i_2, j_1} + A_{i_1, j_2}$.
  • For (i1,i2,j1,j2)=(1,2,1,3)(i_1, i_2, j_1, j_2) = (1, 2, 1, 3), we have $A_{i_1, j_1} + A_{i_2, j_2} = 2 + 3 \leq 3 + 4 = A_{i_2, j_1} + A_{i_1, j_2}$.
  • For (i1,i2,j1,j2)=(1,2,2,3)(i_1, i_2, j_1, j_2) = (1, 2, 2, 3), we have $A_{i_1, j_1} + A_{i_2, j_2} = 1 + 3 \leq 1 + 4 = A_{i_2, j_1} + A_{i_1, j_2}$.
  • For (i1,i2,j1,j2)=(1,3,1,2)(i_1, i_2, j_1, j_2) = (1, 3, 1, 2), we have $A_{i_1, j_1} + A_{i_2, j_2} = 2 + 4 \leq 6 + 1 = A_{i_2, j_1} + A_{i_1, j_2}$.
  • For (i1,i2,j1,j2)=(1,3,1,3)(i_1, i_2, j_1, j_2) = (1, 3, 1, 3), we have $A_{i_1, j_1} + A_{i_2, j_2} = 2 + 1 \leq 6 + 4 = A_{i_2, j_1} + A_{i_1, j_2}$.

We can also see that the property holds for the other quadruples: $(i_1, i_2, j_1, j_2) = (1, 3, 2, 3), (2, 3, 1, 2), (2, 3, 1, 3), (2, 3, 2, 3)$.
Thus, we should print Yes.

Sample Input 2

2 4
4 3 2 1
5 6 7 8

Sample Output 2

No

We should print No because the condition is not satisfied.
This is because, for example, we have $A_{i_1, j_1} + A_{i_2, j_2} = 4 + 8 > 5 + 1 = A_{i_2, j_1} + A_{i_1, j_2}$ for (i1,i2,j1,j2)=(1,2,1,4)(i_1, i_2, j_1, j_2) = (1, 2, 1, 4).

update @ 2024/3/10 09:50:48

}