/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 400 点
問題文
H 行 W 列のグリッドがあります。各マスは、空マスまたは爆弾マスのどちらかです。上から i 行目、左から j 列目のマスを (i,j) と表します。グリッドの情報は H 個の長さ W の文字列 S_1, S_2 , \dots ,S_H によって与えられ、S_i の j 文字目が . のとき (i,j) は空マス、S_i の j 文字目が # のとき (i,j) は爆弾マスです。
また、空マス (i,j) について i 行目にも j 列目にも爆弾マスが存在しないとき、そのマスを 安全な空マス と呼びます。
1 回の移動で今いるマスから、上下左右に隣り合う空マスに移動することができます(爆弾マスには移動できません)。以下の条件を満たす空マス (i, j) の数を求めてください。
- (i,j) から K 回以下の移動で 安全な空マス へ到達できる。
制約
- 1 \le H,W \le 5\times 10^5
- H\times W \le 5\times 10^5
- 0 \le K \le H\times W-1
- S_i は
.と#からなる長さ W の文字列 - H,W,K は整数
入力
入力は以下の形式で標準入力から与えられる。
H W K S_1 S_2 \vdots S_H
出力
条件を満たす空マスの個数を出力せよ。
入力例 1
3 3 1 #.. ... ..#
出力例 1
5
安全な空マス は (2,2) だけです。(2,2) へ 1 回以下の移動で到達できる空マスは (1,2),(2,1),(2,2),(2,3),(3,2) の 5 マスですから、答えは 5 です。
入力例 2
2 3 0 ... ...
出力例 2
6
爆弾マスが存在しないため、6 マスすべてが 安全な空マス です。したがって、どの空マスも移動回数 0 回で条件を満たします。
入力例 3
5 7 2 ..#.... ..#.... ....... ...#... ...#...
出力例 3
29
Score : 400 points
Problem Statement
There is a grid with H rows and W columns. Each cell is an empty cell or a bomb cell. Let (i,j) denote the cell at the i-th row from the top and the j-th column from the left. The grid is given by H length-W strings S_1, S_2 , \dots ,S_H: if the j-th character of S_i is ., (i,j) is an empty cell, and if the j-th character of S_i is #, (i,j) is a bomb cell.
For an empty cell (i,j), if there is no bomb cell in the i-th row nor in the j-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) satisfying the following condition:
- A safe empty cell can be reached from (i,j) in at most K moves.
Constraints
- 1 \le H,W \le 5\times 10^5
- H\times W \le 5\times 10^5
- 0 \le K \le H\times W-1
- S_i is a string of length W consisting of
.and#. - H, W, and K are integers.
Input
The input is given from Standard Input in the following format:
H W K S_1 S_2 \vdots S_H
Output
Output the number of empty cells satisfying the condition.
Sample Input 1
3 3 1 #.. ... ..#
Sample Output 1
5
The only safe empty cell is (2,2). There are five empty cells from which you can reach (2,2) in at most one move: (1,2),(2,1),(2,2),(2,3),(3,2), so the answer is 5.
Sample Input 2
2 3 0 ... ...
Sample Output 2
6
Since there is no bomb cell, all six cells are safe empty cells. Therefore, every empty cell satisfies the condition with zero moves.
Sample Input 3
5 7 2 ..#.... ..#.... ....... ...#... ...#...
Sample Output 3
29