#P7715. Count H-Shaped Patterns

    ID: 20902 Type: Default 1000ms 256MiB

Count H-Shaped Patterns

Count H-Shaped Patterns

You are given an n×mn \times m 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 x1x_1, x2x_2, y1y_1, y2y_2 satisfying the following conditions:

  1. 1x1<x2n1\le x_1<x_2\le n and 1y1<y2m1\le y_1<y_2\le m.
  2. x1+x2x_1+x_2 is even.

Let mid=x1+x22mid=\frac{x_1+x_2}{2} (which is an integer by condition 2). The three segments that form an H-shape are:

  • The left vertical segment: from (x1,y1)(x_1,y_1) to (x2,y1)(x_2,y_1), i.e. all cells in column y1y_1 from row x1x_1 to row x2x_2.
  • The right vertical segment: from (x1,y2)(x_1,y_2) to (x2,y2)(x_2,y_2), i.e. all cells in column y2y_2 from row x1x_1 to row x2x_2.
  • The middle horizontal segment: from (mid,y1)(mid, y_1) to (mid,y2)(mid,y_2), i.e. all cells in row midmid from column y1y_1 to column y2y_2.

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 x1x_1, x2x_2, y1y_1, and y2y_2 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>