Strange tiling (harder version)
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
The difference between the problems "Strange tiling (simpler version)" and "Strange tiling (harder version)" is only in the constraints.
The figure shows an L-tromino in four different positions. Let’s call these figures L-tromino of the first, second, third, and fourth types from left to right.
In each figure, the central cell is highlighted in green.
Marichka needs to tile a rectangular room of size \(n\) by \(m\) with L-tromino tiles, and she asked Zenik for help. Since Zenik did not study to be a builder, he believes that it is enough to place the tiles so that each cell is covered by the same positive number of tiles.
Help Zenik — say whether it is possible to place the L-trominoes in this way, and if so, provide the tiling.
Input
The single line contains two integers \(n\) and \(m\) — the dimensions of the room.
Output
If it is impossible to tile the room, print No in a
single line.
Otherwise, print Yes in the first line.
Next, print the tiling of the room with tiles.
First, print a single matrix of integers of size \(n \times m\) describing the placement of the first type L-tromino tiles. The number in each cell of the matrix means the number of tiles of the first type for which this cell is central. Note that since the tiles cannot extend beyond the room, the first row and the first column of the matrix must be zero.
Then in the same format, print the matrices describing the tiling with the second, third, and fourth type tiles.
The matrices must be separated by an empty line.
Constraints
\(7 \le n, m \le 100\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 8 9 | Yes 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 |
Notes
Note that the tiles cannot extend beyond the borders of the room.
The arrangement of tiles in the example is shown below. In this example, each cell is covered by one tile.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|