CF1333E.Road to 1600
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.

To reach the goal, Egor should research the next topic:
There is an N×N board. Each cell of the board has a number from 1 to N2 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:
- Among all not visited yet cells to which the figure can get in one move, it goes to the cell that has minimal number.
- 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.
- If all cells are already visited, the process is stopped.
Egor should find an N×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×N numbered board, or tell that it doesn't exist.
叶戈尔希望在著名的国际象棋平台 ChessForces 上达到 1600 分的评级,他需要你的帮助!
在开始解题之前,叶戈尔想提醒你国际象棋棋子的走法:
车(Rook)可沿直线向上、向下、向左、向右移动任意格数,且可在任意时刻停止;
后(Queen)则可沿竖直方向及对角线方向移动任意格数。
示例如下:

为达成目标,叶戈尔需研究如下问题:
给定一个 N×N 的棋盘,每个格子中填有 1 到 N2 之间的唯一整数(即所有数字互不相同)。
初始时,某枚棋子位于标号为 1 的格子上(注意:该格子已被视为已访问)。此后每一步均按以下规则进行:
- 在所有尚未访问过且当前棋子一步可达的格子中,选择编号最小者并移动至该格子;
- 若所有一步可达的格子均已访问过,但仍有未访问的格子,则将棋子瞬移至所有未访问格子中编号最小者。若发生瞬移,则需支付 1 个“伏恩”(vun)费用;
- 若所有格子均已被访问,则过程终止。
叶戈尔需构造一个 N×N 的编号棋盘,使得在该编号方案下,车所支付的伏恩总数严格小于后所支付的伏恩总数。请你帮他构造出这样的 N×N 编号棋盘,或判定其不存在。
输入格式
The only line contains one integer N — the size of the board, 1≤N≤500.
唯一的一行包含一个整数 N —— 棋盘的大小,1≤N≤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×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.
输出应包含 N 行。
第 i 行输出 N 个数——即棋盘上第 i 行的数字。数字 1 到 N×N 必须恰好各使用一次。
在你的棋盘上,车(rook)的花费必须严格小于后(queen)的花费。
若不存在满足条件的解,请输出 −1。
若存在多个解,你可以输出其中任意一个。
输入输出样例
输入#1
1
输出#1
-1
输入#2
4
输出#2
4 3 6 12 7 5 9 15 14 1 11 10 13 8 16 2
说明/提示
In case we have 1×1 board, both rook and queen do not have a chance to pay fees.
In second sample rook goes through cells 1→3→4→6→9→5→7→13→2→8→16→11→10→12→15→(1 vun)→14.
Queen goes through 1→3→4→2→5→6→9→7→13→8→11→10→12→15→(1 vun)→14→(1 vun)→16.
As a result rook pays 1 vun and queen pays 2 vuns.
若棋盘大小为 1×1,则车与后均无需支付费用。
在第二个样例中,车经过的格子序列为 1→3→4→6→9→5→7→13→2→8→16→11→10→12→15→(1 vun)→14。
后经过的格子序列为 1→3→4→2→5→6→9→7→13→8→11→10→12→15→(1 vun)→14→(1 vun)→16。
最终,车支付 1 vun,后支付 2 vuns。
输入解题思路,AI测评打分。不知道怎么写?