No.3721 Absurd Basic Constructive
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もしくは右上の雲マークをクリックしてアカウントを作成してください。