P18158 [NWERC 2026] German Bureaucracy

Description

Justus Aurelius is the new intern at *Neptune's Water Engineering, Renovation & Construction* and received his first job from a client. The client wants to renovate the old pond in the garden behind her house. And even though this is Justus Aurelius' first job, she gave him complete freedom to redesign the pond, including the option to shrink or split it. There is just one constraint: the total area covered by water must be at least $25\%$ of the old water area. Armed with a $h \times w$ grid map of the garden and full of creative ideas, Justus Aurelius starts his work. But soon he encounters the good old German bureaucracy… Now he is lost in a jungle of German laws and legal provisions. The following two provisions are causing Justus Aurelius the biggest headache: - § 67 (1) The creation of new water cells is prohibited in residential areas in order to preserve land cells. - § 67 (3) a. To prevent erosion, no cell of land may share more than one side with cells containing water. Being the helpful senior advisor you are, you will help Justus Aurelius with his first project. Propose a new layout for the pond, to allow Justus Aurelius to focus on the creative aspects of the renovation.

Input Format

The input consists of: - One line with two integers $h$ and $w$ ($3 \leq h, w \leq 1000$), the height and width of the map describing the garden. - $h$ lines with $w$ characters, each character being either `#` or `.`, representing a land cell or a water cell, respectively. At least one cell is a water cell.

Output Format

Output a copy of the map where some water cells have been replaced by land cells such that all constraints are fulfilled. It can be proven that this is always possible. If there are multiple valid solutions, you may output any one of them.