DWITE Online Computer Programming Contest, November 2008, Problem 5
There's a shady water dam that might break, so an insurance company wants to calculate the possible damage given a series of scenarios. Given a topography of the region, and the amount of water projected to spill out, the goal is to find out how many of the targets of interest will be submerged, after the water settles.
The input will contain 5 sets of input. First line is an integer , amount of water expected. Second line is an integer , number of columns in a map. Third line is an integer , number of rows in a map. Next lines describe the layout of the area. . . Dot .
is empty space that could be flooded. Number sign #
is land. Capital letter A
is a point of interest; there will be at least 1; it should be treated as empty space, but only this area counts for points. Each set is separated by a whitespace line.
The output will contain 5 lines, the number of points of interest underwater.
Technical details: Water originates at the top-left of the map. Each unit of water occupies one cell on the map. Water normally falls down. If there's ground below, it will move to the right. Once in place (can no longer flow), it could be treated as solid ground, as far as the movement of other units of water is concerned.
Step-by-step diagram: 2 units of water, layout. Asterisk *
represents a moving unit of water. 2nd unit of water reaches A
at the bottom. Even though A
at the top was passed by water, it remains un-submerged at the end, so it's not counted towards the output sum.
*.A. .*A. ..A. *.A. .*A. ..*. ..A* .... ..A.
#.#. #.#. #*#. #*#. #*#. #*#. #*#. #*#* #*#.
###A ###A ###A ###A ###A ###A ###A ###A ###*
Sample Input
2
4
3
..A.
#.#.
###A
4
4
3
..A.
#.#.
###A
5
4
3
..A.
#.#.
###A
Sample Output
1
1
2
Problem Resource: DWITE
Comments
Since the data were split by spaces instead of newlines, the data were updated, and all submissions were rejudged.
Note for some people getting IR, there is leading whitespace before each water value starting from set 2 onwards.