DMOPC '23 Contest 1 P1 - Peak Grid

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 2.0s
Memory limit: 1G

Author:
Problem types

Aschin is interested in the peaks of a grid. A peak is defined as an element of the grid that is the largest in both the row and column containing that element. Please impress Aschin by constructing an N by N grid of distinct integers from 1 to N2 such that it has exactly K peaks.

Constraints

1N2×103

1KN

Subtask 1 [30%]

1N3

Subtask 2 [70%]

No additional constraints.

Input Specification

The first and only line contains the space-separated integers N and K.

Output Specification

Output N lines containing N space-separated integers, a grid of size N by N which contains each integer from 1 to N2 such that there are exactly K peaks. If there are multiple solutions, output any of them. If such a grid does not exist, output 1.

Sample Input

Copy
3 2

Sample Output

Copy
9 1 2
8 7 5
4 3 6

Explanation for Sample

6 and 9 are the 2 peaks.


Comments

There are no comments at the moment.