# Flood on the top floor

There has been a water incident on the top floor of a building, and one apartment has suffered some water damage. As in, a lot of water damage. The entire apartment is filled waist deep with dihydrogen monoxide. As a contractor, you are tasked with getting the liquid out. All plumbing is out of order due to the aforementioned incident, and there is no feasible way to get any pumping equipment up into the apartment. The only way the get the water out is to break some walls and floors to allow the water to flow freely into a well on the ground floor (marked red).

You propose a way to get the water out along the hallways to avoid flooding any of the other apartments. However, the landlord will have to pay for repairs on the rooms used to pass the water through, and the price is solely dependent on the affected area (i.e. repairing one square of the hallway costs the same as repairing one square of an apartment). For that reason, the landlord will gladly allow you to pass through another apartment if that means a smaller overall area will be used to get the water out.

Rules:

• You can make a hole in the wall or floor of any room (apartment or hallway) currently containing water, but not the outer walls of the building.
• Once a hole is made on a wall piece, the water spreads out through it to fill the available area evenly.
• Once a hole is made on a floor piece, all of the water flows down to the next floor below and fills the available area evenly.
• Once the water reaches the well, all of it will flow in and the mission is complete.
• There is no extra cost in fixing holes made on walls/floors, so make as many holes as is necessary to get the water out.
• Water does not flow upwards.
• There is no elevator or stairwell, because who thinks of those things when drawing a building.

How many squares will the landlord need to repair after you've gotten the water out? While keeping the number of squares at a minimum, what is the minimum number of other apartments (gray rectangles) that you must temporarily fill with water?

Initial situation

Rejected proposal (Holes are marked with X's)

• dihydrogen monoxide. wow +1. and optimization tag? Commented Aug 13, 2019 at 9:18
• what is the cost of repairing a wall piece?? 0? Commented Aug 13, 2019 at 9:20
• @OmegaKrypton Thanks, tag added. The cost of repairing holes made on walls/floors is zero. I'll add a mention about that in the description.
– Jafe
Commented Aug 13, 2019 at 9:26
• in the rejected proposal, why will all hallway grids be flooded? wont all water go through the hole directly? Commented Aug 13, 2019 at 9:28
• @OmegaKrypton Hmm, true. The idea was to make the holes one by one starting where the water is now, but that doesn't really appear in the rules as written...
– Jafe
Commented Aug 13, 2019 at 9:48

I may need some clarification on counting but I think I've found a solution in which the landlord needs to repair 38 squares while filling just 3 other apartments with water.

Solution

Partial Reasoning

Except for the 5th floor and the 1st floor, every floor has its 3rd column as entirely hallway. This means that we need to either enter the hallway on some floor that is not the 1st or we need to flood the apartment on the left on the 1st floor.

In the latter case, the most efficient way to get to the well from the first floor is to break through to the apartment at the top and go straight down over the well. This would damage 20 squares on the first floor. We must flood at least four squares on each of the other floors but, since the four square apartment on the 2nd floor is not linked to either of the four square apartments on the 3rd floor, this means at least one of the floors will have to have at least six squares flooded. There is a 38 square solution in this case which floods 5 other apartments as shown:

In the former case, we must choose which hallway to flood. The hallway on the 4th floor has just 11 squares, 4 less than the next smallest (that is not the 1st floor). With this choice, it is not too difficult to find a path which passes through just one apartment on each of the other floors.
Furthermore, if we try to flood the hallway on any other floor, we find we are forced into making decisions which flood more than 38 squares.

• This is the intended answer. It would be nice to know how you arrived at the solution, though.
– Jafe
Commented Aug 13, 2019 at 12:18
• @jafe I'll try to add some reasoning about why I came to this conclusion Commented Aug 13, 2019 at 13:02

28 squares (not counting the already flooded top floor apartment or ground floor hallway - 48 if you include them) and three apartments.

Holes are marked in pink

5th floor hole: One of the top two squares in the flooded apartment. This floods the 4th floor hallway (11 squares)
4th floor hole: End of the hallway on the right edge of the building. This floods the apartment in the bottom right corner (9 squares)
3rd floor hole: Middle of that apartment. This floods the apartment in the bottom right corner (4 squares)
2nd floor hole: Top right of that apartment. This floods the apartment in the bottom right corner (4 squares)
1st floor hole: One of the top two squares in the apartment. This floods the ground floor hallway

• Why would the ground floor hallway not count? Commented Aug 14, 2019 at 1:43
• hexomino did not count the ground floor. Commented Aug 14, 2019 at 2:22
• Hexomino’s hole in the first floor was directly above the well, so the water went straight from the first floor into the well — it didn’t flood the rest of the ground floor, @EugeneStyer. Commented Aug 14, 2019 at 11:10