题目描述
Problem Description
There is a grid with $ N $ rows and $ M $ columns. The cell at the $ i $-th row from the top and the $ j $-th column from the left is represented by $ (i,j) $. In particular, the top-left cell is $ (1,1) $ and the bottom-right cell is $ (N,M) $. The state of the grid is represented by a 2D array $ s $, where $ s_{ij} $ is # if there is an obstacle at cell $ (i,j) $, and . if there is no obstacle.
Takahashi placed a robot on one of the cells in the grid, facing one of the four directions (up, down, left, or right). The robot moves straight for at least one cell in the direction it is facing, then turns 90 degrees to the right, and moves straight again for at least one cell before stopping. During this process, none of the cells the robot passed through (including the cell it was placed on and the cell it stopped at) had obstacles, and the robot did not move outside the grid.
Determine the number of possible ordered pairs of the cell where the robot was placed and the cell where it stopped.
Input Format
The input is given from the standard input in the following format:
$ N $ $ M $ $ s_{11}...s_{1M} $ $ : $ $ s_{N1}...s_{NM} $
Output Format
Output the number of possible ordered pairs of the cell where the robot was placed and the cell where it stopped.
Sample Input and Output
Sample Input #1
3 3
..#
...
#.#
Sample Output #1
9
Sample Input #2
2 5
.#.#.
..#..
Sample Output #2
2
Sample Input #3
6 8
#......#
##....##
#.#..#.#
#..##..#
#......#
#......#
Sample Output #3
182
Notes/Hints
Constraints
- $2 \leq N,M \leq 2 \times 10^3$
- $ s_{ij} $ is either
#or.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分