Since the recent U.S. midterm elections, policymakers have begun to heed residents who opposed unchecked data center construction. Several areas are now tightening their building standards for data centers considerably.
A sign opposing data center construction in Kansas, USA, May 2026
Photo: Catboy69 / Wikimedia Commons / CC BY 4.0
https://commons.wikimedia.org/wiki/File:Anti_ai_data_center_4_censored.png
https://creativecommons.org/licenses/by/4.0/
For ChatDOJ, Inc., stopping data center construction is not an option. In the spirit of corporate compliance, the company wants to build a new data center while encroaching as little as possible on areas where the authorities prohibit construction.
The map of the area where ChatDOJ, Inc., is looking for a site is a grid with rows and columns.
Each cell is marked as either a site where construction is allowed (.) or one where it is prohibited (#).
The data center is a large facility that occupies a rectangle of consecutive rows and consecutive columns. It may be rotated by degrees to suit the road layout, in which case it occupies consecutive rows and consecutive columns. The entire data center must lie inside the map.
The first line contains and , the number of rows and columns in the map, separated by a space.
The second line contains and , the height and width of the data center, separated by a space.
The next lines describe the map. Each line is a string of length consisting only of and .
Print one integer: the minimum number of cells where construction is prohibited that are covered by the data center.
In the first example, placing the data center without rotation in rows through and columns through covers no prohibited cells. The answer is .
Even if there is no way to build the data center without encroaching on a prohibited area, the company will not give up on the project.
Find the minimum number of cells where construction is prohibited that the data center must cover.
.#| 3 | 100 | No additional constraints. |
In the second example, any placement without rotation covers prohibited cells in the third column. After rotating by degrees, the data center can be placed in rows through and columns through without covering any prohibited cells, so the answer is .
In the third example, any placement covers the center cell, the only prohibited cell, regardless of orientation. The answer is .