Problem:


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



Sample input:
2


Sample output:
1
1 0

Submission status: Wrong Answer

Solution code:
n = int(input())
ans_list = []
for i in range(n):
    if i % 2 == 1:
        ans_list.append((i,0))
    if i % 6 == 1:
        for j in range(2,n,2):
            ans_list.append((i,j))
    elif i % 6 == 4:
        for j in range(1,n,2):
            ans_list.append((i,j))

print(len(ans_list))
for i in ans_list:
    print(*i)

Submission status: Wrong Answer

Solution code:
n = int(input())
odd = [item for item in range(3, n+1, 2)]
even = [item for item in range(2, n+1, 2)]
ans = []
added = [0] * n
for i in range(2, n+1, 2):
    ans.append((1, i))
for i in range(2, n+1, 3):
    if i % 2 == 0:
        for item in odd:
            ans.append((item, i))
    else:
        for item in even:
            ans.append((item, i))
for i in range(n, 0, -1):
    if (i - 2) % 3 == 0:
        continue
    if i % 2 == 0:
        for item in odd:
            ans.append((item, i))

ans.sort()

print(len(ans))
for a, b in ans:
    print(a - 1, b - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
odd = [item for item in range(3, n+1, 2)]
even = [item for item in range(2, n+1, 2)]
ans = []
for i in range(2, n+1, 2):
    ans.append((1, i))
for i in range(2, n+1, 3):
    if i % 2 == 0:
        for item in odd:
            ans.append((item, i))
    else:
        for item in even:
            ans.append((item, i))
if n % 4 == 0 and (n - 2) % 6 != 0:
    for i in range(n, -1, -1):
        if i % 2 == 0 and (i // 2) % 2 == 0:
            for item in odd:
                ans.append((item, i))
            break

print(len(ans))
for a, b in ans:
    print(a - 1, b - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
odd = [item for item in range(3, n+1, 2)]
even = [item for item in range(2, n+1, 2)]
ans = []
for i in range(2, n+1, 2):
    ans.append((1, i))
for i in range(2, n+1, 3):
    if i % 2 == 0:
        for item in odd:
            ans.append((item, i))
    else:
        for item in even:
            ans.append((item, i))
if n % 4 == 0:
    for i in range(n, -1, -1):
        if i % 2 == 0 and (i // 2) % 2 == 0:
            for item in odd:
                ans.append((item, i))
            break

print(len(ans))
for a, b in ans:
    print(a - 1, b - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
odd = [item for item in range(3, n+1, 2)]
even = [item for item in range(2, n+1, 2)]
ans = []
for i in range(2, n+1, 2):
    ans.append((1, i))
for i in range(2, n+1, 3):
    if i % 2 == 0:
        for item in odd:
            ans.append((item, i))
    else:
        for item in even:
            ans.append((item, i))
for i in range(n, -1, -1):
    if i % 2 == 0 and (i // 2) % 2 == 0:
        for item in odd:
            ans.append((item, i))
        break

print(len(ans))
for a, b in ans:
    print(a - 1, b - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
odd = [item for item in range(3, n+1, 2)]
even = [item for item in range(2, n+1, 2)]
ans = []
for i in range(2, n+1, 2):
    ans.append((1, i))
for i in range(2, n+1, 3):
    if i % 2 == 0:
        for item in odd:
            ans.append((item, i))
    else:
        for item in even:
            ans.append((item, i))
for i in range(n, -1, -1):
    if (i // 2) % 2 == 0:
        for item in odd:
            ans.append((item, i))
        break

print(len(ans))
for a, b in ans:
    print(a - 1, b - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
odd = [item for item in range(3, n+1, 2)]
even = [item for item in range(2, n+1, 2)]
ans = []
for i in range(2, n+1, 2):
    ans.append((1, i))
for i in range(2, n+1, 3):
    if i % 2 == 0:
        for item in odd:
            ans.append((item, i))
    else:
        for item in even:
            ans.append((item, i))

print(len(ans))
for a, b in ans:
    print(a - 1, b - 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
odd = [item for item in range(3, n+1, 2)]
even = [item for item in range(2, n+1, 2)]
ans = []
for i in range(2, n+1, 2):
    ans.append((1, i))
for i in range(2, n+1, 3):
    if i % 2 == 0:
        for item in odd:
            ans.append((item, i))
    else:
        for item in even:
            ans.append((item, i))

print(len(ans))
for a, b in ans:
    print(a, b)

Submission status: Accepted

Solution code:
n=int(input())
ans=[]
for i in range(n-1):
  if i%2:
    ans+=[(i,0)]
for i in range(n-1):
  if i%6==1:
    for j in range(2,n):
      if j%2==0:
        ans+=[(i,j)]
  if i%6==4:
    for j in range(n):
      if j%2:
        ans+=[(i,j)]
for j in range(n):
  if(n-1+j)%2:
    ans+=[(n-1,j)]
print(len(ans))
for x,y in ans:
  print(x,y)

Submission status: Accepted

Solution code:
n = int(input())
ans_list = []
for i in range(n):
    if i % 2 == 1:
        ans_list.append((i,0))
    if i % 6 == 1:
        for j in range(2,n,2):
            ans_list.append((i,j))
    elif i % 6 == 4:
        for j in range(1,n,2):
            ans_list.append((i,j))

if n % 3 != 2:
    for i in range(1,n):
        if (n - 1 + i) % 2 == 1:
            ans_list.append((n-1,i))

print(len(ans_list))
for i in ans_list:
    print(*i)

Submission status: Accepted

Solution code:
n = int(input())
odd = [item for item in range(3, n+1, 2)]
even = [item for item in range(2, n+1, 2)]
ans = []
added = [0] * n
for i in range(2, n+1, 2):
    ans.append((1, i))
for i in range(2, n+1, 3):
    if i % 2 == 0:
        for item in odd:
            ans.append((item, i))
    else:
        for item in even:
            ans.append((item, i))
for i in range(n, 0, -1):
    if (i - 2) % 3 == 0:
        continue
    if i % 2 == 0:
        for item in odd:
            ans.append((item, i))
        break

ans.sort()

print(len(ans))
for a, b in ans:
    print(a - 1, b - 1)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines

import numpy as np

N = int(readline())

grid = np.zeros((N,N),np.int8)

grid[::2,::2] = 1
grid[1::2,1::2] = 1

grid[::6,1::6] = 1
grid[::6,5::6] = 1
grid[2::6,1::6] = 1
grid[2::6,3::6] = 1
grid[4::6,3::6] = 1
grid[4::6,5::6] = 1

grid[0,:] = 1
grid[-1,:] = 1
grid[:,0] = 1
grid[:,-1] = 1

grid[::2,::2] = 0
grid[1::2,1::2] = 0

x,y = np.where(grid==1)

print(len(x))
for cell in zip(x,y):
    print(*cell)

Submission status: Accepted

Solution code:
N = int(input())
MAX = 170000

ans = []
for i in range(1,N,2):
    for j in range(0,N,2):
        if (i//2)%3 == 0:
            ans.append((i,j))
        elif (i//2)%3 == 1:
            if (j//2)%2 == 0: ans.append((i,j))
        else:
            if (j//2)%2 == 1: ans.append((i,j))

for i in [0,N-1]:
    for j in range(N):
        if (i+j)%2:
            ans.append((i,j))
            ans.append((j,i))
ans = set(ans)
print(len(ans))
for x,y in ans:
    print('{0} {1}'.format(x,y))

#v = [['.' if (i+j)%2 else '#' for j in range(N)] for i in range(N)]
#for x,y in ans:
#    if (i+j)%2: raise
#    v[x][y] = 'a'
#for row in v:
#    print(''.join(row))

Submission status: Accepted

Solution code:
n=input()
r=range
d=[(i,0)for i in r(1,n,2)]
for i in r(1,n,3):d+=[(i,j)for j in r(1+i%2,n,2)]
if n%3==1:d+=[(n-1,i)for i in r(2-n%2,n,2)]
print len(d)
print"\n".join(" ".join(map(str,e))for e in d)