Bull in a China Shop (Bronze)
Time limit2sMemory limit512 MB
Pick the two pieces from K candidates that shift without rotation to cover the original grid exactly once.
- Level
Easy3 of 10
- Topics
- Brute force, Simulation
- Solved
- No attempts yet
Problem
Farmer John decided that his home needs more decoration. At the local china shop he finds a delicate glass cow figurine that fits perfectly on the mantel above his fireplace, so he decides to buy it.
The shape of the figurine is given as an grid of characters (). A '#' is a cell that belongs to the figurine and a '.' is a cell that does not. Here is an example with .
#..#....
####....
########
.##.####
...####.
...#..#.
...#..#.
........
Right before John can pay, a bull runs through the shop and breaks his figurine along with many other glass objects on the shelves. The figurine breaks into 2 pieces, and they end up mixed in with the pieces lying on the ground (). Each of the pieces is given as an grid of characters, in the same format as the figurine.
Find the two pieces John has to glue back together. The pieces were neither rotated nor flipped when they fell, so John only has to shift them horizontally and vertically and then lay one over the other. If the two pieces really came from his figurine, he can shift them so that every '#' of the original figurine belongs to exactly one of the two pieces: the shifted pieces share no '#', and together they form the original shape exactly.
A piece may be shifted by any amount horizontally and vertically, but it may not be shifted so far that one of its '#' characters leaves the grid. The '#' characters of a piece do not have to form a single connected region. When a piece consists of several separate clumps, all of its clumps move by the same amount.
Input
The first line contains and , separated by a space. The next lines contain the grid of the original figurine. The following lines contain the grids of the pieces John found on the ground, one piece after another.
Output
Print the indices of the two pieces of John's figurine on one line, separated by a space. Each index is between and , and the smaller index comes first. A solution always exists and it is unique.