No.2112 All 2x2 are Equal
タグ : / 解いたユーザー数 91
作問者 :
bayashiko
/ テスター :
👑
KowerKoint2010
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 9and 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もしくは右上の雲マークをクリックしてアカウントを作成してください。