307288: CF1333E. Road to 1600
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Road to 1600
题意翻译
给一个$n\times n$的棋盘,上面有$n\times n$个$[1,n\times n]$之间的整数且互不相同。 棋盘上有一个车和一个后,初始都在数字1处。 走法如下: - 车能到达同一行或同一列的任何(没有被自己访问过的)位置,后能到达同一行,同一列或同一斜线上任何(没有被自己访问过的)位置(可见图) - 每次车和后都会走到能到达的数字中最小的。如果不存在,那么会花费1的代价传送到整个棋盘中没有被自己访问过的数字最小的位置。 求一种方案,满足车走完的代价**严格小于**后走完的代价 ,或者输出-1表示不存在这样的方案 $n\le 500$题目描述
Egor wants to achieve a rating of 1600 points on the well-known chess portal ChessForces and he needs your help! Before you start solving the problem, Egor wants to remind you how the chess pieces move. Chess rook moves along straight lines up and down, left and right, as many squares as it wants. And when it wants, it can stop. The queen walks in all directions vertically and diagonally at any distance. You can see the examples below. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1333E/73b9d5dec0fb48461c487105879fa605baff377a.png)To reach the goal, Egor should research the next topic: There is an $ N \times N $ board. Each cell of the board has a number from $ 1 $ to $ N ^ 2 $ in it and numbers in all cells are distinct. In the beginning, some chess figure stands in the cell with the number $ 1 $ . Note that this cell is already considered as visited. After that every move is determined by the following rules: 1. Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number. 2. If all accessible cells were already visited and some cells are not yet visited, then the figure is teleported to the not visited cell that has minimal number. If this step happens, the piece pays a fee of $ 1 $ vun. 3. If all cells are already visited, the process is stopped. Egor should find an $ N \times N $ board on which the rook pays strictly less vuns than the queen during the round with this numbering. Help him to find such $ N \times N $ numbered board, or tell that it doesn't exist.输入输出格式
输入格式
The only line contains one integer $ N $ — the size of the board, $ 1\le N \le 500 $ .
输出格式
The output should contain $ N $ lines. In $ i $ -th line output $ N $ numbers — numbers on the $ i $ -th row of the board. All numbers from $ 1 $ to $ N \times N $ must be used exactly once. On your board rook must pay strictly less vuns than the queen. If there are no solutions, print $ -1 $ . If there are several solutions, you can output any of them.
输入输出样例
输入样例 #1
1
输出样例 #1
-1
输入样例 #2
4
输出样例 #2
4 3 6 12
7 5 9 15
14 1 11 10
13 8 16 2