E - Not Equal Rectangle Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 800

問題文

N \times M のマス目があり、あなたはこれから全てのマスに 1 以上 25 以下の整数を 1 つずつ書き込みます。上から i 行目、左から j 列目のマスに書き込む整数を a_{i,j} とします。

以下の条件を満たす整数の書き込み方を一つ求めてください。本問題の制約下で、条件を満たす整数の書き込み方が必ず存在することが証明できます。

  • 任意の整数 1\leq x_1 < x_2\leq N,1\leq y_1 < y_2 \leq M について、a_{x_1,y_1},a_{x_1,y_2},a_{x_2,y_1},a_{x_2,y_2} が全て一致してはならない。

制約

  • 2 \leq N , M \leq 500
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N M 

出力

条件を満たす書き込み方の 1 つを、以下の形式で出力せよ。

a_{1,1} a_{1,2} \ldots a_{1,M}
a_{2,1} a_{2,2} \ldots a_{2,M}
\vdots
a_{N,1} a_{N,2} \ldots a_{N,M}

条件を満たす解が複数存在する場合、どれを出力しても正解とみなされる。


入力例 1

2 3

出力例 1

1 1 1
1 2 3

(x_1,x_2,y_1,y_2) の組として考えられるのは (1,2,1,2),(1,2,2,3),(1,2,1,3)3 つです。

どの組についても 4 マスに書かれた数字が全て一致してはいないので、この出力は条件を満たします。

Score : 800 points

Problem Statement

We have a grid with N \times M squares. You will fill every square with an integer between 1 and 25 (inclusive). Let a_{i,j} be the integer to be written in the square at the i-th row from the top and j-th column from the left.

Find a way to fill the squares to satisfy the condition below. It can be proved that, under the Constraints of this problem, such a way always exists.

  • For any integers 1\leq x_1 < x_2\leq N,1\leq y_1 < y_2 \leq M, it must not be the case that a_{x_1,y_1},a_{x_1,y_2},a_{x_2,y_1},a_{x_2,y_2} are all equal.

Constraints

  • 2 \leq N , M \leq 500
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M 

Output

Print one way to fill the squares to satisfy the condition, in the format below:

a_{1,1} a_{1,2} \ldots a_{1,M}
a_{2,1} a_{2,2} \ldots a_{2,M}
\vdots
a_{N,1} a_{N,2} \ldots a_{N,M}

If there are multiple solutions, printing any of them will be accepted.


Sample Input 1

2 3

Sample Output 1

1 1 1
1 2 3

(x_1,x_2,y_1,y_2) can be one of (1,2,1,2),(1,2,2,3),(1,2,1,3).

For any of them, the numbers written in the squares are not all equal, so this output satisfies the condition.