The Problem
A doomsday scenario is described by three numbers on a single line, n
, m
, and p
. Following that line are n
lines with m
values per line. Each value represents the total units of water each cell can hold.
The following p
lines describe the weather for the next p
days. 1 unit of rain falls on a single cell each day. If the amount of water in a cell exceeds the amount it can hold, that cell floods. If multiple adjacent cells are at full capacity, they are treated as one cell that share common neighbors (think Minesweeper when you click on a group of blanks).
- A single middle cell has 4 neighbors
- Two adjacent, full capacity middle cells are treated as one cell that has 6 neighbors
- A single corner cell has 2 neighbors
- A single wall cell has 3 neighbors
When a cell floods, a flood event occurs. All excess water is evenly distributed to its neighbors. If that causes one or more neighbors to flood, then another flood event occurs. This continues until the water has settled, or the city has completely flooded.
Example Input
7 5 3
3 2 3 4 5
2 2 0 3 4
1 1 2 3 3
4 1 2 2 2
4 1 1 2 2
4 4 1 2 2
4 4 2 2 2
0 0
1 2
4 3
0 0
means it rained on row 1, col 11 2
means it rained on row 2, col 3 (which can hold zero water and immediately floods!)
After p
days of rain, if the city is completely flooded, output Sink. Otherwise, output Swim.
Example Output
Swim
Assumptions
- Input may be provided through stdin, read from "city.txt", or accepted as an argument. All three are allowed so as not to invalidate any answers already posted.
- Water capacities will be non-negative integers.
40+ teams of undergrad college students (from A&M, UT, LSU, Rice, Baylor, etc.) competing in a programming contest with a variety of languages available could not solve this problem in 5 hours. Because of that, I can't help but mention that there is a catch to this puzzle that makes the solution trivial. Shortest code still wins, because I am that confident that the shortest code will also solve the puzzle.
n
lines ofm
values or the other way around? Your example doesn't match the written specification. \$\endgroup\$0.25
units to each adjacent cell (assuming a single middle flooded cell)? \$\endgroup\$