Bees
InterviewTime limit1sMemory limit512 MB
Given an n by m hexagonal honeycomb's initial honey pattern, apply the rule that each cell fills next day exactly when an odd number of its neighbors were filled, and print the state after k days.
- Level
Medium6 of 10
- Topics
- Bit manipulation, Simulation, Matrix, Math
- Solved
- No attempts yet
Problem
Bees store honey in a honeycomb every day. The honeycomb is a grid of regular hexagonal cells arranged in rows and columns. During the night the larvae eat all of the honey, so the honeycomb is completely empty when a day begins. The bees do not pick cells at random. Which cells receive honey is decided by which cells held honey on the previous day. A cell holds honey exactly when the number of its neighboring cells that held honey on the previous day is odd, and it stays empty otherwise. A cell is not its own neighbor.
Two adjacent rows are offset by half a cell. The first cell of row 1 sits above and to the left of the first cell of row 2. The neighbors of the cell in row and column are therefore:
- and in the same row
- , , , when is odd
- , , , when is even
Positions outside the honeycomb are not neighbors.

The picture shows the honeycomb of the first example input.
Input
The first line contains three natural numbers , and separated by spaces (, ). Here is the number of rows of the honeycomb, is the number of columns, and is the number of days that pass.
Each of the next lines contains characters. A '#' means the cell holds honey at the start, and a '.' means it does not.
Output
Print the state of the honeycomb after days in lines, in the same format as the input.