J - Connected Checkerboard Editorial /

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 100

問題文

N マス × N マスのチェスボードがあります。

最も左上のマスから、右に i マス、下に j マス進んだマスを (i, j) と呼びます。特に、最も左上のマスは (0, 0) です。

i+j が偶数であるようなマス (i, j) は黒、それ以外のマスは白で塗られています。

これから、いくつかの白いマスを黒に塗り替えることで以下の条件が満たされるようにします。

  • マス (0, 0) から始めて、辺を共有する黒いマスに移動するという操作を繰り返したときに、全ての黒いマスにたどり着くことができる。

170000 個以下のマスを黒く塗り替えることで条件を達成してください。

制約

  • 1 \leq N \leq 1,000

入力

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

N

出力

条件を達成するために黒く塗り替えたマスの情報を以下の形式で出力せよ。

K
x_1 y_1
x_2 y_2
:
x_K y_K

これは、全部で K 個のマスを黒く塗り替えており、i 番目に (x_i, y_i) のマスを黒く塗り替えたことを表す。

判定

以下の全ての条件を満たしているときのみ、その出力は正解とみなされる。

  • 0 \leq K \leq 170000
  • 0 \leq x_i, y_i \leq N-1
  • 全ての i に対して x_i + y_i は奇数。
  • i \neq j ならば (x_i, y_i) \neq (x_j, y_j)
  • 出力された全てのマスを黒く塗ることで問題文中の条件が達成されている。

入力例 1

2

出力例 1

1
1 0

入力例 2

4

出力例 2

3
0 1
2 1
2 3

Score : 100 points

Problem Statement

We have an N×N checkerboard.

From the square at the upper left corner, a square that is i squares to the right and j squares below is denoted as (i, j). Particularly, the square at the upper left corner is denoted as (0, 0).

Each square (i, j) such that i+j is even, is colored black, and the other squares are colored white.

We will satisfy the following condition by painting some of the white squares:

  • Any black square can be reached from square (0, 0) by repeatedly moving to a black square that shares a side with the current square.

Achieve the objective by painting at most 170000 squares black.

Constraints

  • 1 \leq N \leq 1,000

Input

The input is given from Standard Input in the following format:

N

Output

Print the squares to paint in the following format:

K
x_1 y_1
x_2 y_2
:
x_K y_K

This means that a total of K squares are painted black, the i-th of which is (x_i, y_i).

Judging

The output is considered correct only if all of the following conditions are satisfied:

  • 0 \leq K \leq 170000
  • 0 \leq x_i, y_i \leq N-1
  • For each i, x_i + y_i is odd.
  • If i \neq j, then (x_i, y_i) \neq (x_j, y_j).
  • The condition in the statement is satisfied by painting all specified squares.

Sample Input 1

2

Sample Output 1

1
1 0

Sample Input 2

4

Sample Output 2

3
0 1
2 1
2 3