Seismic Design
Time limit1sMemory limit512 MB
Given a grid with one epicenter, barriers, and buildings, count how many buildings collapse under a main shock (range 2) and the aftershocks it causes (range 1).
- Level
Medium4 of 10
- Topics
- Matrix, BFS, Simulation
- Solved
- No attempts yet
Problem
A magnitude 5.0 earthquake struck suddenly early this morning. The epicenter is one cell in a grid-shaped region of cells. The earthquake from the epicenter is called the main shock, and the weaker quake caused by collapsing buildings is called an aftershock. The main shock spreads up, down, left, and right from the epicenter up to cells in each direction, and the aftershock spreads up, down, left, and right up to cell. Both the main shock and aftershocks affect buildings. A building without seismic design collapses as soon as the earthquake reaches it, but a building with seismic design collapses only after the earthquake reaches it times. When the main shock or an aftershock meets a seismic barrier or goes outside the grid, it stops spreading. The movement of the earthquake is shown in the figures below.
Input
The first line contains two integers () and (), separated by a space.
From the second line, the next lines each contain a string of length . The string uses the following 5 characters, and there is exactly one epicenter.
@: epicenter.: normal road*: building without seismic design#: building with seismic design|: seismic barrier
Output
Print the number of collapsed buildings and the number of buildings that did not collapse, separated by a space, on one line.



