問題一覧 > 通常問題

No.2112 All 2x2 are Equal

レベル : / AI推定難易度 : 1750 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 91
作問者 : bayashiko / テスター : 👑 p-adic KowerKoint2010 noimi MtSaka
お気に入りにしたユーザー ProblemId : 8385 / 自分の提出
問題文最終更新日: 2022-10-28 18:44:31
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 366 (順位表) の他の問題:

Problem Statement

There is a grid with $H$ rows and $W$ columns. The cell in the $i$-th row from the top and the $j$-th column from the left is called cell $(i,j)$.

Among the ways to write the integers from $1$ to $H×W$ in the cells of this grid, $1$ of each, does there exist one that satisfies the following condition?

  • Let $A_{i,j}$ be the integer written in cell $(i,j)$. There exists an integer $S$ such that $A_{i,j}+A_{i+1,j}+A_{i,j+1}+A_{i+1,j+1}=S$ for every pair of positive integers $(i,j)$ satisfying $1\le i \le H-1,1\le j \le W-1$.

If one exists, show an example of it; if none exists, report that.

Input

$H\ W$

  • $2\le H,W\le 1000$
  • All input values are integers.

Output

If a way of writing that satisfies the condition exists, print Yes on line $1$, and on the following $H$ lines print $1$ way of writing that satisfies the condition.

If there are multiple ways of writing that satisfy the condition, you may print any of them.

Yes
$A_{1,1}\ A_{1,2} \ .. \ A_{1,W}$
$A_{2,1}\ A_{2,2} \ .. \ A_{2,W}$
:
$A_{H,1}\ A_{H,2} \ .. \ A_{H,W}$
If no way of writing satisfies the condition, print No on a single line, followed by a newline.
No

Sample

Sample 1
Input
3 3
Output
Yes
1 5 3 
9 8 7
4 2 6

For every $(i,j)$, we have $A_{i,j}+A_{i+1,j}+A_{i,j+1}+A_{i+1,j+1}=23$, so this way of writing indeed satisfies the condition.

1 7 4
8 3 5
6 2 9
and others also satisfy the condition. ($S=19$)

Sample 2
Input
2 2
Output
Yes
1 2
4 3

Every way of writing satisfies the condition.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。