問題一覧 > 通常問題

No.3721 Absurd Basic Constructive

レベル : / AI推定難易度 : 725 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 120
作問者 : 👑 kencho / テスター : 👑 p-adic uruzunyaa
お気に入りにしたユーザー ProblemId : 13563 / 自分の提出
問題文最終更新日: 2026-11-02 04:25:17
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
グリッド構築24題 (順位表) の他の問題:

Problem Statement

Write integers into the cells of an $N \times N$ grid so that the following $2$ conditions are satisfied.

  • Exactly $1$ integer is written in each cell.
  • Each integer between $1$ and $N^2$, inclusive, is written in exactly $1$ cell.

That is, the integers are written so that the $N^2$ integers between $1$ and $N^2$, inclusive, and the $N^2$ cells are in $1$-to-$1$ correspondence.

Let cell $(i, j)$ denote the cell in the $i$-th row from the top and the $j$-th column from the left, and let $A_{i, j}$ be the integer written in cell $(i, j)$. Find one way of writing the integers such that there are exactly $K$ pairs of integers $(i, j)\ (1 \leq i, j \leq N)$ satisfying the following condition.

  • The maximum of the integers written in the rectangular region with cell $(1, 1)$ as its top-left corner and cell $(i, j)$ as its bottom-right corner is $A_{i,j}$.
    • More formally, $\displaystyle \max_{\substack{1 \leq r \leq i \\ 1 \leq c \leq j}} A_{r,c} = A_{i,j}$ holds.

If no such way of writing exists, output -1.

Constraints

  • All input values are integers.
  • $1 \leq N \leq 1000$
  • $0 \leq K \leq N^2$

Input

The input is given from standard input in the following format.

$N\ K$

Output

If there exists a way of writing such that there are exactly $K$ pairs of integers $(i, j)\ (1 \leq i, j \leq N)$ satisfying the condition, output one such way in the following format. If none exists, output -1.

$A_{1, 1}\ A_{1, 2}\ \ldots\ A_{1, N}$
$A_{2, 1}\ A_{2, 2}\ \ldots\ A_{2, N}$
$\vdots$
$A_{N, 1}\ A_{N, 2}\ \ldots\ A_{N, N}$

Print a newline at the end.

Visualizer

A web-based visualizer for the output is available here.

During the contest, sharing visualization results and mentioning solutions or analysis are prohibited. Please be careful.

In principle, we do not accept questions about the specifications of the visualizer. Please use it only as a supplementary tool.

Sample

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

The $5$ pairs $(i, j) = (1, 1), (1, 3), (2, 1), (2, 2), (3, 1)$ satisfy the condition, and they correspond to the $5$ cells painted yellow in the figure below.

Sample 2
Input
1 0
Output
-1

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