#P7715. Count H-Shaped Patterns
Count H-Shaped Patterns
Count H-Shaped Patterns
You are given an grid consisting of white and black cells. A cell is white if it is denoted by a dot ('.') and black if it is denoted by a hash ('#').
An H-shape is defined by selecting four integers , , , satisfying the following conditions:
- and .
- is even.
Let (which is an integer by condition 2). The three segments that form an H-shape are:
- The left vertical segment: from to , i.e. all cells in column from row to row .
- The right vertical segment: from to , i.e. all cells in column from row to row .
- The middle horizontal segment: from to , i.e. all cells in row from column to column .
An H-shape is valid if every cell on these three segments is white. Two H-shapes are considered the same if and only if their values of , , , and are identical.
Your task is to count the number of different valid H-shapes in the grid.
inputFormat
The first line contains two integers $n$ and $m$ ($2\le n, m\le 300$) --- the number of rows and columns of the grid.
Each of the next $n$ lines contains a string of length $m$ consisting only of characters .
and #
, where .
represents a white cell and #
represents a black cell.
It is guaranteed that the grid dimensions allow at least one possible H-shape selection (though it might not pass the white condition).
outputFormat
Output a single integer, the number of valid H-shapes in the grid.
sample
3 3
...
...
...
3
</p>