#ABC472D. 疯狂炸弹 / Bomber Mad

疯狂炸弹 / Bomber Mad

Problem Statement

There is a grid with HH rows and WW columns. Each cell is an empty cell or a bomb cell. Let (i,j)(i,j) denote the cell at the ii-th row from the top and the jj-th column from the left. The grid is given by HH length-WW strings S1,S2,,SHS_1, S_2 , \dots ,S_H: if the jj-th character of SiS_i is ., (i,j)(i,j) is an empty cell, and if the jj-th character of SiS_i is #, (i,j)(i,j) is a bomb cell.

For an empty cell (i,j)(i,j), if there is no bomb cell in the ii-th row nor in the jj-th column, that cell is called a safe empty cell.

In one move, you can move from the current cell to an adjacent empty cell in the up, down, left, or right direction (you cannot move to a bomb cell). Find the number of empty cells (i,j)(i, j) satisfying the following condition:

  • A safe empty cell can be reached from (i,j)(i,j) in at most KK moves.

Constraints

  • 1H,W5×1051 \le H,W \le 5\times 10^5
  • H×W5×105H\times W \le 5\times 10^5
  • 0KH×W10 \le K \le H\times W-1
  • SiS_i is a string of length WW consisting of . and #.
  • HH, WW, and KK are integers.

Input

The input is given from Standard Input in the following format:

  • HH WW KK
  • S1S_1
  • S2S_2
  • \vdots
  • SHS_H

Output

Output the number of empty cells satisfying the condition.

3 3 1
#..
...
..#
5

The only safe empty cell is (2,2)(2,2). There are five empty cells from which you can reach (2,2)(2,2) in at most one move: (1,2),(2,1),(2,2),(2,3),(3,2)(1,2),(2,1),(2,2),(2,3),(3,2), so the answer is 55.

2 3 0
...
...
6

Since there is no bomb cell, all six cells are safe empty cells. Therefore, every empty cell satisfies the condition with zero moves.

5 7 2
..#....
..#....
.......
...#...
...#...
29