Codeforces Round 293 (Div. 2)
F
Pasha and Pipe
Codeforces
2300
原题
← E→
翻译中…

On a certain meeting of a ruling party "A" minister Pavel suggested to improve the sewer system and to create a new pipe in the city.

翻译中…

The city is an $*n* × *m*$ rectangular squared field. Each square of the field is either empty (then the pipe can go in it), or occupied (the pipe cannot go in such square). Empty squares are denoted by character '$.$', occupied squares are denoted by character '$#$'.

翻译中…

The pipe must meet the following criteria:

翻译中…
  • the pipe is a polyline of width $1$,
  • the pipe goes in empty squares,
  • the pipe starts from the edge of the field, but not from a corner square,
  • the pipe ends at the edge of the field but not in a corner square,
  • the pipe has at most $2$ turns ($90$ degrees),
  • the border squares of the field must share exactly two squares with the pipe,
  • if the pipe looks like a single segment, then the end points of the pipe must lie on distinct edges of the field,
  • for each non-border square of the pipe there are exacly two side-adjacent squares that also belong to the pipe,
  • for each border square of the pipe there is exactly one side-adjacent cell that also belongs to the pipe.
翻译中…

Here are some samples of allowed piping routes:

翻译中…

           ....#            ....#            .*..#
           *****            ****.            .***.
           ..#..            ..#*.            ..#*.
           #...#            #..*#            #..*#
           .....            ...*.            ...*.

翻译中…

Here are some samples of forbidden piping routes:

翻译中…

           .**.#            *...#            .*.*#
           .....            ****.            .*.*.
           ..#..            ..#*.            .*#*.
           #...#            #..*#            #*.*#
           .....            ...*.            .***.

翻译中…

In these samples the pipes are represented by characters '$*$'.

翻译中…

You were asked to write a program that calculates the number of distinct ways to make exactly one pipe in the city.

翻译中…

The two ways to make a pipe are considered distinct if they are distinct in at least one square.

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*, *m*$ ($2 ≤ *n*, *m* ≤ 2000$) — the height and width of Berland map.

翻译中…

Each of the next $*n*$ lines contains $*m*$ characters — the map of the city.

翻译中…

If the square of the map is marked by character '$.$', then the square is empty and the pipe can through it.

翻译中…

If the square of the map is marked by character '$#$', then the square is full and the pipe can't through it.

翻译中…

Output

翻译中…

In the first line of the output print a single integer — the number of distinct ways to create a pipe.

翻译中…

Note

翻译中…

In the first sample there are 3 ways to make a pipe (the squares of the pipe are marked by characters '$*$'):

翻译中…

       .*.        .*.        ...
       .*#        **#        **#
       .*.        ...        .*.

翻译中…

样例

Input #1
3 3
...
..#
...
Output #1
3
InputCopy OutputCopy
Input #2
4 2
..
..
..
..
Output #2
2
InputCopy OutputCopy
Input #3
4 5
#...#
#...#
###.#
###.#
Output #3
4
InputCopy OutputCopy
题目信息
题号
518F
时间限制
4 s
内存限制
512 MB
标签
二分
暴力
组合数学
动态规划
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。