#P1228. Carpet Tiling Puzzle

    ID: 14389 Type: Default 1000ms 256MiB

Carpet Tiling Puzzle

Carpet Tiling Puzzle

In an ancient Arab kingdom there was a palace with a square grid labyrinth. Inside the labyrinth, the princess stood on one square. The king decided that any suitor who could cover every cell except the princess's cell with specially shaped carpets would win her hand. The carpet pieces can only be in one of four L-shaped orientations (see figure below). Additionally, each cell can be covered by at most one carpet layer. The labyrinth is a square grid of size \(2^k \times 2^k\). Can you cover the board (except the princess's cell) using L-shaped carpet pieces?

Carpet Shapes

Note: The princess's cell is not to be covered and is marked as 0. Each carpet piece (an L-shaped tromino) must cover exactly three cells and is assigned a unique positive integer identifier (the same number in all three cells).

inputFormat

The input consists of two lines:

  • The first line contains a single integer \(k\) (with \(2^k\) being the board size).
  • The second line contains two integers \(r\) and \(c\) (1-indexed), indicating the row and column where the princess stands.

You may assume that \(k\) is such that \(2^k\) is at most 128.

outputFormat

Output the board after tiling. The board has \(2^k\) rows and \(2^k\) columns. Each cell is output as an integer separated by a space. The princess's cell is denoted by 0, and each placed L‐shaped carpet (tromino) is given a unique positive integer identifier (each tromino uses the same identifier for its three cells).

sample

1
1 1
0 1

1 1

</p>