#P9837. WangLeGeWang Card Placement Game

    ID: 22982 Type: Default 1000ms 256MiB

WangLeGeWang Card Placement Game

WangLeGeWang Card Placement Game

In this problem, you are given a pyramid‐shaped board with n rows. The i-th row has i cells so that the total number of cells is \(\frac{n(n+1)}{2}\). There is an infinite deck of cards numbered \(1,2,\dots,n\). You must place exactly one card into every cell. The placement must obey the following rule in all levels:

  • The first element (the leftmost card) in each row must be distinct.

The game has three levels of difficulty:

  • Level 0: No extra conditions.
  • Level 1: In addition to the basic rule, within every row, every two adjacent cards must be different, and furthermore, every unordered pair formed by two adjacent cards (i.e. \(\{a,b\}\)) must be unique across all rows.
  • Level 2: All the restrictions of Level 1 hold, and additionally the cards in each row must all be distinct.

It can be shown that under the game conditions there always exists a valid placement. For instance, when \(n=5\), one valid arrangement for Level 2 is illustrated below:

Sample

Given \(n\) and a level (which will be 0, 1, or 2), find any valid placement that passes the corresponding level.

Note on the restrictions:

  • For Level 0, you only need to ensure that the first element of every row is distinct.
  • For Level 1, although repeated cards in a row are allowed (except no two adjacent cards are equal), the adjacent unordered pairs across the board must be unique.
  • For Level 2, every row is a permutation (hence, all cards are distinct within that row) and thus automatically satisfies the adjacent distinct condition. In addition, the unordered adjacent pairs across rows are unique. In fact, the total number of adjacent pairs across the board is \(0+1+2+\cdots+(n-1)=\frac{n(n-1)}{2}\) while the total number of unordered pairs \(\{i,j\}\) with \(1\le i<j\le n\) is also \(\frac{n(n-1)}{2}\); hence the set of unordered adjacent pairs exactly forms the complete set of pairs from \(1\) to \(n\).

inputFormat

The input consists of a single line containing two integers \(n\) and \(level\) (0, 1, or 2), where \(n\) is the board side length.

outputFormat

Output \(n\) lines. The \(i\)-th line should contain \(i\) space‐separated integers representing the card numbers assigned to the cells of the \(i\)-th row.

sample

3 0
1

2 1 3 1 1

</p>