DMOPC '23 Contest 1 P2 - Knights on Chessboard

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 2.0s
Memory limit: 1G

Author:
Problem types

The genius chess player A. Robbie gives you a puzzle on an empty N by N chessboard. To complete this puzzle, you must place at most N2+3N5 knights such that every square on the chessboard contains a knight or is being attacked by a knight. Formally, a knight on square (x,y) attacks a square (i,j) if |xi|=1 and |yj|=2, or |xi|=2 and |yj|=1. Can you solve A. Robbie's ultimate challenge?

Constraints

8N2×103

Subtask 1 [10%]

N=8

Subtask 2 [90%]

No additional constraints.

Input Specification

The first and only line contains the integer N.

Output Specification

Output N lines where each line contains N space-separated binary values, where 0 represents an empty square, and 1 represents a knight. If there are multiple solutions, output any of them. If a solution does not exist, output 1.

Sample Input

Copy
8

Sample Output

Copy
0 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 0 0 1 1 1
1 1 1 0 0 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 0

Explanation for Sample

This sample is only shown to clarify the format of the output. Note that this output is incorrect, as there are greater than N2+3N5 knights on the board, although all squares are either covered by a knight or attacked by a knight.


Comments


  • 3
    rnpmat08_v2  commented on Dec. 15, 2023, 4:07 p.m.

    is the limit rounded up or down?


    • 5
      BalintR  commented on Dec. 16, 2023, 2:42 a.m.

      It is rounded down. x denotes the floor function, the greatest integer not more than x.