#P9879. Maximizing Check Patterns
Maximizing Check Patterns
Maximizing Check Patterns
Professor Shou is given an (n \times m) board. Some cells are precolored black, some are precolored white, and the rest are uncolored. He likes check patterns, so he wants to color all uncolored cells in order to maximize the number of 2×2 check pattern squares on the board.
A 2×2 square is said to have a check pattern if its four cells are colored in one of the following ways:
[
\begin{matrix}
B & W\
W & B
\end{matrix}
\quad \text{or} \quad
\begin{matrix}
W & B\
B & W
\end{matrix}
]
Here, (B) ("biancu" in Corsican) represents a white cell and (W) ("wakuda" in Chewa) represents a black cell.
inputFormat
The first line contains two integers (n) and (m) (with (2 \le n, m \le 500)) — the number of rows and columns of the board. Each of the next (n) lines contains a string of length (m) consisting of the characters:
• (B) : the cell is precolored white;
• (W) : the cell is precolored black;
• (.) : the cell is uncolored.
outputFormat
Output a single integer, the maximum number of 2×2 check pattern squares that can be achieved after coloring all uncolored cells.
sample
2 2
..
..
1