#K77387. Construct a Grid with Specific Consecutive Counts

    ID: 34853 Type: Default 1000ms 256MiB

Construct a Grid with Specific Consecutive Counts

Construct a Grid with Specific Consecutive Counts

You are given a positive integer (n). Your task is to construct an (n \times n) grid of integers following these rules:

  1. For each integer (k) where (1 \le k \le n), you must place exactly (k) occurrences of (k) in the grid.
  2. The (k) occurrences for each number must be placed consecutively in one direction (either horizontally or vertically).
  3. Any cell that is not filled by the consecutive block for any (k) should remain as (0).

For example, if (n=3), one valid grid is:

1 2 2
3 3 3
0 0 0

In the above grid, the number 1 appears exactly 1 time, 2 appears exactly 2 times consecutively (in row 1), and 3 appears exactly 3 times consecutively (in row 2).

Note: It is guaranteed that a solution exists by placing the blocks greedily from (k=1) to (k=n) in row-major order.

inputFormat

The input consists of a single integer (n) ((1 \le n \le 50)), representing the size of the grid.

outputFormat

Output the (n \times n) grid. Each of the (n) lines should contain (n) integers separated by a single space.## sample

1
1

</p>