N-Queen (mod N)
Time limit1sMemory limit512 MB
Given N, place N queens on an N by N board whose opposite edges are joined, so no two share a row, column, or wrapped diagonal. Print one valid placement, or -1 if none exists.
- Level
Medium6 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Given an chessboard, print one way to place queens so that no two queens attack each other. The square in row and column has coordinates . The top-left square is , and the bottom-right square is . The opposite edges of the board are joined together. Two queens at and attack each other if at least one of the following four conditions holds: (1) , (2) , (3) , (4) .
Input
The first line contains an integer . ()
Output
If queens can be placed, print , , , , on the first line, where is the column number of the queen in row . ()
If queens cannot be placed, print -1.