[Community Puzzle] Flood the World

( I created the topic, because I did not find any for this puzzle. )
https://www.codingame.com/training/expert/flood-the-world

While the puzzle is interesting, I think this sentence in the statement is rather misleading:
As such, the volume of water on the left is the same as on the right (6x "~").

This “6x ~” implies as if the water volume is to be calculated base on the char counts in the grid.
(Because in the provided ascii art example, the real areas of the trapezoids are NOT the same.)

After wasting an hour on a ‘char grid flood’ based solution, and after checking some test cases, now it seems to me that this approach is incorrect and we have to calculate the volumes (or areas in 2D) exactly, and taking into account the slopes as well.

EDIT: the trapezoid areas are indeed the same in the example, my mistake. But the ‘char counting’ approach still seems to be a dead end to me, because only the statement example has 45 degrees slopes, other test cases are more varied…

2 Likes

My approach was to split the landscape into vertical bands based on segment intersections, and find out which bands get flooded before others. I had to use recursive ‘banding’ to compute larger composite bands :stuck_out_tongue: but it worked out in the end.

1 Like

It didn’t cross my mind, but yes, it could be misleading at first. I’ve added a foot note in the description of the problem to clarify this matter.

2 Likes

Hi, could you send validators in private message please I have all test cases running but I didn’t validate validators 2,7 and 11. I’m a bit messed up with all the cases and this would help me solving the puzzle. I have spent quite a lot of time on it yet, my strategy is to compute the volumes and set of segments defining them, necessary for each town to be raised by water level, and then sorting towns according to which they submerge when submerged, and if a tie occurs, necessary volume comes in to seperate cases.
All the best

You may send me your code in private message and I’ll take a look and get back to you.

It’s OK thanks I have changed my approach : from source I fill in by smallest volume available, if source is overflooded, it goes vertically to water level, and last town not flooded wins. I used the Thales theorem to fill in a given trapeze by a given volume. All the best