#P11752. Hanging Painting

    ID: 13845 Type: Default 1000ms 256MiB

Hanging Painting

Hanging Painting

You are given a rectangular wall divided into n rows and m columns. Some of the regions on the wall have nails, denoted by #, and other regions do not have nails, denoted by ..

A way to hang a painting is considered legal if and only if:

  • The painting occupies a rectangular region on the wall.
  • The occupied rectangular region contains at most one nail.

Calculate the number of legal ways to hang a painting.

Note: If a rectangle contains 0 or 1 nail, it is considered legal.

The number of nails in any rectangle can be computed by the following formula using a prefix sum array:

\( S(i_1, j_1, i_2, j_2) = P[i_2+1][j_2+1] - P[i_1][j_2+1] - P[i_2+1][j_1] + P[i_1][j_1] \)

inputFormat

The first line contains two integers n and m (the number of rows and columns of the wall, respectively).

Then follow n lines, each consisting of m characters. Each character is either # (denoting a nail) or . (denoting an empty region).

outputFormat

Output a single integer: the number of legal ways to hang the painting.

sample

2 2
..
..
9