Tiling the Shower Floor (Small)
Time limit2sMemory limit512 MB
Cover a 2^K by 2^K grid with L-shaped trominoes leaving one drain cell open, choosing the lexicographically smallest numbering.
- Level
Medium7 of 10
- Topics
- Divide and conquer, Recursion, Implementation
- Solved
- No attempts yet
Problem
On his first day at the training camp, Mingyu is called in and told to lay the shower floor again. The person who laid it before covered the drain along with every other cell.
The shower floor is a square whose side length is a power of two. That worker used only square tiles, and such tiles cannot leave a single cell open for the drain. Mingyu decides to use L shaped tiles that cover three cells instead of the four cell square tiles. An L shaped tile is a square with one cell removed, and it may be rotated by 90 degrees into any of the four orientations.
You are given the size of the floor and the position of the drain. Cover every cell except the drain with L shaped tiles so that no two tiles overlap and no cell is left uncovered. A tile may not stick out of the floor.
Input
The first line contains a natural number (). The side length of the floor is .
The second line contains two natural numbers and , separated by a space, giving the position of the drain (). The bottom left cell is and the top right cell is .
Output
Print lines. Line holds the row with , from to , with one space between values, so the top row is printed first. Print -1 for the drain cell, and for every other cell print the number of the tile that covers it.
Several layouts can be valid, so one answer is fixed by the following rule. Scan the cells in printing order, top line first and left to right inside a line, and give each tile you meet for the first time the next unused number starting from . There are tiles, so the numbers run from to . Among all valid layouts numbered this way, print the one whose printed numbers, read in printing order, form the lexicographically smallest sequence.
If no valid covering exists, print -1 on a single line.