NL-Queen (mod N)
Time limit2sMemory limit1024 MB
Place N queens on an N by N board whose opposite edges connect, so none attack each other, and print one placement that is not k-linear, or -1 if impossible.
- Level
Hard8 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Given an chessboard, print one special way to place queens so that no two queens attack each other. The square in row and column is . The top-left square is and the bottom-right square is . Opposite edges of the board are connected, so the board wraps around. Two queens at and attack each other if at least one of the following four conditions holds.
In a placement where no two queens attack each other, let be the column of the queen in row . If an integer satisfies for every , the placement is called -linear. If the placement is not -linear for any integer , it is called special.
Input
The first line contains an integer . ()
Output
If queens can be placed, print on the first line. ()
If queens cannot be placed, print -1.