Square Tiles (Large)
InterviewTime limit5sMemory limit512 MB
For each test case, decide whether all blue cells can be tiled with non-overlapping 2x2 red tiles and print the tiled picture or Impossible.
- Level
Easy3 of 10
- Topics
- Greedy, Matrix, Implementation
- Solved
- No attempts yet
Problem
You sell geometric pictures. Each picture is made of 1x1 square tiles packed into a grid with no gaps. Here is one example.
.##..
.####
.####
.##..
Blue tiles are written as # and white tiles as .. You use no other color.
Some customers do not like blue and ask you to replace every blue tile in a picture with red tiles. Red tiles only come in the larger 2x2 size, which makes the job harder.
You may cover any 2x2 square of blue tiles with a single red tile, and you repeat this as often as you like. A red tile cannot overlap another red tile, it cannot cover a white tile, and it cannot stick out of the picture. Every blue tile has to end up covered. The picture above can be covered like this.
./\..
.\//\
./\\/
.\/..
One red tile is written as two / characters in its top left and bottom right cells, and two \ characters in the other two cells.
Given a blue and white picture, decide whether you can turn it into a red and white picture this way, and draw the result when you can.
Input
The first line contains the number of test cases, . test cases follow.
Each test case starts with a line holding and , the number of rows and the number of columns of a picture, separated by a space. The next lines contain exactly characters each and describe the picture. # is a blue tile and . is a white tile.
Limits
Output
For each test case, first print a line of the form Case #x:, where is the test case number starting from 1.
If the blue tiles can all be covered by red tiles that do not overlap, print the finished picture as lines of characters each. Red tiles are written with / and \, white tiles with .. When a covering exists it is the only one, so there is exactly one correct picture.
If no covering exists, print a single line reading Impossible instead of the picture.