407702: GYM102878 D Life Game

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Life Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Scientists try to figure out how does the initial biosphere look like. So they design an experiment with serval micro-creatures in a matrix grid and observe their behavior.

A grid point can exist at most $$$1$$$ micro-creature and there are only two states of their life activities, which are * for alive and . for death.

At each time point, all the micro-creatures will transfer between two states. And the transformation will only depend on states of the 8 micro-creatures around it.

Let l, r $$$(0 \leq l \leq r \leq 8)$$$ be the suitable living range of the micro-creatures. Only if the number of alive micro-creatures around it is not greater than r and not less than l, the creature will become or keep alive, otherwise it will keep death or die due to overcrowding or loneliness.

Now, you are given the initial state of the micro-creatures in a matrix grid, please predict what will be them looked like after a while.

Input

The first line gives two integers $$$n, m (1 \leq n, m \leq 100)$$$, which means that there are $$$n * m$$$ grids on the matrix grid, guarantee that

The second line gives two integers $$$l, r (0 \leq l \leq r \leq 8 )$$$, which represents that it is suitable for survival when the number of living creatures around the creature is $$$[l, r]$$$ .

The third line gives only one integer $$$t (1 \leq t \leq 10^3)$$$, which means that the time point you should predict.

In the next $$$n$$$ line, each line gives $$$m$$$ characters "*" or "." to represent there is life or no life on the grid in the initial state.

Output

A matrix of $$$n \times m$$$ composed of "*" and "." to represent the state at the time $$$t$$$. Please notiece that the initial state is considered as time 1.

ExamplesInput
5 5
2 3
8
*...*
.*.*.
..*..
.*.*.
*...*
Output
.....
.....
.....
.....
.....
Input
5 5
3 6
8
*...*
.*.*.
..*..
.*.*.
*...*
Output
*****
*...*
*...*
*...*
*****
Note

The evolution of case 1 is as follows:

It will finally stop in the last state.

The evolution of case 2 is as follows:

Finally it loops through the three states.

加入题单

算法标签: