問題一覧 > 通常問題

No.3092 Tired Queen

レベル : / AI推定難易度 : 1950 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 49
作問者 : RiRinbaru / テスター : autumn09 downer hamo21 Yotugi ygussany
お気に入りにしたユーザー ProblemId : 11595 / 自分の提出
問題文最終更新日: 2025-04-06 13:27:00
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
QUPC2024 (順位表) の他の問題:

Problem Statement

There is an $N×N$ grid, and a chess queen is placed on cell $(1, 1)$. You can move the queen as in chess. Specifically, in $1$ move, you can perform $1$ of the following $2$ types of operations.

  • Operation 1: Move it vertically or horizontally. That is, letting $(x, y)$ be the current cell, move the piece to a cell where exactly one of the $x$ coordinate and the $y$ coordinate is the same.
  • Operation 2: Move it diagonally. That is, letting $(x, y)$ be the current cell, move the piece to a cell that has the same $x+y$ or the same $x-y$ and is not the current cell.
The queen gets tired very easily, so after performing one of the operations, the next operation must be the other $1$ operation.
Construct a way to place the piece on every cell of the grid exactly $1$ time, with no repetition, by repeatedly moving it with the above operations $N^2-1$ times from the cell where the queen is initially located. The first operation may be either of the two.

Input

$N$
  • $1\leq N\leq 10^3$
  • All inputs are integers

Output

If no solution exists, output -1.
If one exists, output $N$ lines in the following format.

$A_{1, 1}$ $A_{1, 2}$ $A_{1, 3}$ $...$ $A_{1, N}$
$A_{2, 1}$ $A_{2, 2}$ $A_{2, 3}$ $...$ $A_{2, N}$
$A_{3, 1}$ $A_{3, 2}$ $A_{3, 3}$ $...$ $A_{3, N}$
$:$
$A_{N, 1}$ $A_{N, 2}$ $A_{N, 3}$ $...$ $A_{N, N}$
$A_{i, j}$ represents the position in the visiting order at which the piece is placed on cell $(i, j)$, where being on cell $(1, 1)$ counts as the $1$-st.
If there are multiple possible constructions, output any 1 of them.
Print a newline at the end.

Sample

Sample 1
Input
3
Output
1 4 8
6 2 3
7 5 9

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。