J - Connected Checkerboard Editorial /

Time Limit: 2 sec / Memory Limit: 256 MB

配点 : 100100

問題文

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

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

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

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

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

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

制約

  • 1N1,0001 \leq N \leq 1,000

入力

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

NN

出力

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

KK
x1x_1 y1y_1
x2x_2 y2y_2
::
xKx_K yKy_K

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

判定

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

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

入力例 1Copy

Copy
2

出力例 1Copy

Copy
1
1 0

入力例 2Copy

Copy
4

出力例 2Copy

Copy
3
0 1
2 1
2 3

Score : 100100 points

Problem Statement

We have an N×NN×N checkerboard.

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

Each square (i,j)(i, j) such that i+ji+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)(0, 0) by repeatedly moving to a black square that shares a side with the current square.

Achieve the objective by painting at most 170000170000 squares black.

Constraints

  • 1N1,0001 \leq N \leq 1,000

Input

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

NN

Output

Print the squares to paint in the following format:

KK
x1x_1 y1y_1
x2x_2 y2y_2
:
xKx_K yKy_K

This means that a total of KK squares are painted black, the ii-th of which is (xi,yi)(x_i, y_i).

Judging

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

  • 0K1700000 \leq K \leq 170000
  • 0xi,yiN10 \leq x_i, y_i \leq N-1
  • For each ii, xi+yix_i + y_i is odd.
  • If iji \neq j, then (xi,yi)(xj,yj)(x_i, y_i) \neq (x_j, y_j).
  • The condition in the statement is satisfied by painting all specified squares.

Sample Input 1Copy

Copy
2

Sample Output 1Copy

Copy
1
1 0

Sample Input 2Copy

Copy
4

Sample Output 2Copy

Copy
3
0 1
2 1
2 3


2025-04-14 (Mon)
10:15:39 +00:00