Кухня та котик
Limits: 2 sec., 256 MiB
Зовсім недавно Зеник покрив підлогу кухні новою плиткою. Але Марічці ця плитка не сподобалася, тому треба зробити все знову.
Зеник узяв Марічку (щоб їй уже точно сподобалося), і вони поїхали у відомий будівельний магазин «Чотири пінгвіни» та купили там багато плитки розміром \(1 \times 2\).
Здавалося б, залишилося повторити все, що він уже робив раніше, але не все так просто.
Кухня має форму прямокутника розміром \(n \times m\) і складається з одиничних квадратів. Але в квадраті з координатами \((x, y)\) заснув котик, і Зеник не хоче його будити.
Допоможіть Зенику знайти таке довільне розміщення плитки, щоб квадрат, у якому лежить котик, був непокритим або скажіть, що цього не можна зробити.
Зауважте, плитку не можна різати, проте можна повертати на 90 градусів.
Input
У єдиному рядку містяться чотири цілі числа \(n\), \(m\), \(x\), \(y\) — висота та ширина кухні й координати квадрата, у якому спить котик.
Output
Якщо покрити підлогу, не потривоживши котика, неможливо, виведіть
одне число -1.
Інакше виведіть \(n\) рядків, кожен із яких складається з \(m\) великих та малих англійських літер. Літери позначають, яка саме плитка покриває відповідний одиничний квадрат. Однакові літери позначають ту саму плитку, різні — різну.
Клітинку, у якій спить котик, позначте символом @.
Constraints
\(1 \le n, m \le 10\),
\(1 \le x \le n\),
\(1 \le y \le m\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 3 5 2 2 | AAaax B@ZZx Bccbb |
| Input (stdin) | Output (stdout) |
|---|---|
| 1 5 1 2 | -1 |
Notes
У другому прикладі видно, що між котиком та лівою стіною кухні потрібно покрити один квадрат. Оскільки плитку різати не можна, підлогу ніяк не вийде замостити.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
Kitchen and the Cat - Editorial
We are given the size of a rectangle that must be covered with \(2 \times 1\) tiles. One of the cells must not be covered. We need to tell whether all cells except the given one can be covered, and if so, print the tiling.
It is easy to see that if \(n\) or \(m\) is even, there is no answer, since then the total number of cells to cover is odd, which is impossible.
When \(n\) and \(m\) are odd, a tiling may still be impossible (the second test of the statement). Color the rectangle like a chessboard, with the top left cell white. Then there is one more white cell than black ones. Since a tile covers one white and one black cell, the cat must sleep on a white cell. A cell is white if \(x+y\) is even.
If \(n\) and \(m\) are odd and \(x+y\) is even, the rectangle can be tiled as follows. It is easy to cut off a strip of width 2 from the right side:
(In the same way we can cut off a strip of width 4, 6, 8, ..., that is, any even width.)
The same goes for the other sides:
After that, either the whole area is covered, or a \(3 \times 3\) square with the marked cell inside remains. Such a square is easy to tile: it is enough to lay 4 tiles "around" the marked cell.
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|