102241: [AtCoder]ABC224 B - Mongeness

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

Description

Score : $200$ points

Problem Statement

We have a grid with $H$ horizontal rows and $W$ vertical columns, where each square contains an integer. The integer written on the square at the $i$-th row from the top and $j$-th column from the left is $A_{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 $(i_1, i_2, j_1, j_2)$ such that $1 \leq i_1 < i_2 \leq H$ and $1 \leq j_1 < j_2 \leq W$.

Constraints

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

Input

Input is given from Standard Input in the following format:

$H$ $W$
$A_{1, 1}$ $A_{1, 2}$ $\cdots$ $A_{1, W}$
$A_{2, 1}$ $A_{2, 2}$ $\cdots$ $A_{2, W}$
$\vdots$
$A_{H, 1}$ $A_{H, 2}$ $\cdots$ $A_{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 $(i_1, i_2, j_1, j_2)$ such that $1 \leq i_1 < i_2 \leq H$ and $1 \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 $(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 $(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 $(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 $(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 $(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 $(i_1, i_2, j_1, j_2) = (1, 2, 1, 4)$.

Input

题意翻译

有一个 $h$ 行 $w$ 列的方阵,记方阵上数第 $i$ 排左数第 $j$ 列上的数为 $a_{i,j}$ 。求有多少满足如下要求的 $i_1,j_1,i_2,j_2$ 的组合: $a_{i_1,j_1}+a_{i_2,j_2}≤a_{i_2,j_1}+a_{i_1,j_2}$ ?( $1≤i_1<i_2≤h,1≤j_1<j_2≤w$ )

Output

得分:200分 部分 问题描述 我们有一个包含$H$行和$W$列的网格,每个方格上都包含一个整数。从上数第$i$行、从左数第$j$列的方格上写的数为$A_{i, j}$。 确定这个网格是否满足以下条件。 引用 对于任意一组四元整数$(i_1, i_2, j_1, j_2)$,只要满足$1 \leq i_1 < i_2 \leq H$和$1 \leq j_1 < j_2 \leq W$,则有$A_{i_1, j_1} + A_{i_2, j_2} \leq A_{i_2, j_1} + A_{i_1, j_2}$成立。 部分 约束条件 * $2 \leq H, W \leq 50$ * $1 \leq A_{i, j} \leq 10^9$ * 输入中的所有值都是整数。 部分 输入 输入以标准输入的形式给出,格式如下: $H$ $W$ $A_{1, 1}$ $A_{1, 2}$ $\cdots$ $A_{1, W}$ $A_{2, 1}$ $A_{2, 2}$ $\cdots$ $A_{2, W}$ $\vdots$ $A_{H, 1}$ $A_{H, 2}$ $\cdots$ $A_{H, W}$ 部分 输出 如果网格满足问题描述中的条件,则输出Yes;否则,输出No。 部分 样例输入1 3 3 2 1 4 3 1 3 6 4 1 部分 样例输出1 Yes 有九组四元整数$(i_1, i_2, j_1, j_2)$满足$1 \leq i_1 < i_2 \leq H$和$1 \leq j_1 < j_2 \leq W$。对于其中的每一组,$A_{i_1, j_1} + A_{i_2, j_2} \leq A_{i_2, j_1} + A_{i_1, j_2}$都成立。下面是一些例子。 * 对于$(i_1, i_2, j_1, j_2) = (1, 2, 1, 2)$,我们有$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}$。 * 对于$(i_1, i_2, j_1, j_2) = (1, 2, 1, 3)$,我们有$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}$。 * 对于$(i_1, i_2, j_1, j_2) = (1, 2, 2, 3)$,我们有$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}$。 * 对于$(i_1, i_2, j_1, j_2) = (1, 3, 1, 2)$,我们有$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}$。 * 对于$(i_1, i_2, j_1, j_2) = (1, 3, 1, 3)$,我们有$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}$。 我们还可以看到,对于其他四元组$(i_1, i_2, j_1, j_2) = (1, 3, 2, 3), (2, 3, 1, 2), (2, 3, 1, 3), (2, 3, 2, 3)$,这个性质也成立。

加入题单

上一题 下一题 算法标签: