#P15492. [ICPC 2025 APC] Control Towers

[ICPC 2025 APC] Control Towers

Description

You are an architect tasked with designing the new airport in your city. After you have completed your design, you just realize you forgot to allocate spaces for the control towers.

The layout of the new airport can be represented by a 2D grid of rr rows and cc columns, with the rows numbered from 11 to rr (top to bottom) and the columns numbered from 11 to cc (left to right). The cell in row ii and column jj is denoted by (i,j)(i, j). Each cell can either be occupied or empty.

You need to place four control towers (numbered from 11 to 44), each in a different empty cell. To allow easier communication between different towers, for all k=1,2,3k = 1, 2, 3, you want tower kk and tower k+1k + 1 to be placed either in the same row or in the same column.

You want to calculate the number of ways to place the control towers to satisfy the requirements above. Two ways are considered different if there exists kk where control tower kk is placed in different cells.

Input Format

The first line of input contains two integers rr and cc (1r,c20001 \leq r, c \leq 2000). Each of the next rr lines contains a string of cc characters. The jj-th character in the ii-th line is #\# if cell (i,j)(i, j) is occupied; otherwise, it is \cdot (dot).

Output Format

Output the number of ways to place the control towers to satisfy the requirements above.

3 4
.#.#
#...
.###
10
4 6
######
#.#.#.
.#.#.#
######
0
1 10
..........
5040
1 10
##########
0

Hint

Explanation for the sample input/output #1

Figure A.1 illustrates all 1010 possible ways to place the control towers, where the cells numbered 11, 22, 33, and 44 represent control towers 11, 22, 33, and 44 respectively.

:::align{center}

Figure A.1: All 1010 possible ways to place the control towers. :::

Explanation for the sample input/output #2

It is impossible for any control tower in row 22 to be in the same column as any control tower in row 33. Since there are not enough empty cells to place all four control towers in the same row, there is no way to place the control towers to satisfy the requirements above.

Explanation for the sample input/output #3

All 10×9×8×7=504010 \times 9 \times 8 \times 7 = 5040 ways of control tower positions satisfy the requirements above.

Explanation for the sample input/output #4

There is no empty cell to place any control tower.