Zombie Virus
InterviewTime limit2sMemory limit1024 MB
Two viruses spread one cell per hour from fixed sources on a grid; when both reach a cell within the same hour, virus 3 forms there. Count final cells of each type.
- Level
Medium6 of 10
- Topics
- BFS, Graph, Simulation, Implementation
- Solved
- No attempts yet
Problem
There is a village in the shape of an x grid. One day a zombie virus breaks out and spreads quickly through the village. An investigation of the virus revealed three types, numbered , , and .
The viruses behave as follows.
- Viruses and have a low mortality rate but are highly contagious. They spread simultaneously to the villages adjacent up, down, left, and right, and take 1 hour to fully infect a village.
- A virus can spread to another village only after the current village is fully infected, and it does not invade a village that another virus has fully infected.
- If a virus of a different type arrives at a village before one virus has fully infected it, virus is created.
- Virus has a high mortality rate and, being weakly contagious, no longer spreads from the village it infects.
- A village holding a cure cannot be infected.



Villages infected with virus and virus have appeared. Given that the viruses spread as far as they can, find how many villages are infected with virus , virus , and virus , respectively.
Input
The first line gives () and ().
Starting from the second line, lines each give the state of villages. A village state is one of the following.
- : a village holding a cure
- : a village not yet infected
- : a village infected with virus
- : a village infected with virus
Exactly one village infected with virus and exactly one village infected with virus are given.
Output
Print the numbers of villages infected with virus , virus , and virus , separated by spaces, on one line.