P15345 [GeeksforGeeks] B5e2a639b39537ea71e4551a4274383bda1c9a34
提高-
题目描述

Geek is in a maze of size N * M. Each cell in the maze is made of either '.' or '#'. An empty cell is represented by '.' and an obstacle is represented by '#'. If Geek starts at cell (R, C), find how many different empty cells he can pass through while avoiding the obstacles. He can move in any of the four directions but he can move up at most U times and he can move down atmost D times.

Example 1:
Input:
N = 3, M = 3
R = 1, C = 0
U = 1, D = 1
mat = {{'.', '.', '.'},
{'.', '#', '.'},
{'#', '.', '.'}}
Output: 5
Explanation: Geek can reach
(1, 0), (0, 0), (0, 1), (0, 2), (1, 2)
Example 2:
Input:
N = 3, M = 4
R = 1, C = 0
U = 1, D = 2
mat = {{'.', '.', '.'},
{'.', '#', '.'},
{'.', '.', '.'},
{'#', '.', '.'}}
Output: 10
Explanation: Geek can reach all the
cells except for the obstacles.

Your Task:
You don't need to read input or print anything. Complete the function numberOfCells() which takes N, M, R, C, U, D and the two dimensional character array mat[][] as input parameters and returns the number of cells geek can visit( If he is standing on obstacle he can not move).
Constraints:
1 ≤ N*M ≤ 10^{6}
mat[i][j] = '#" or '.'
0 ≤ R ≤ N-1
0 ≤ C ≤ M-1

输入格式

见题面

输出格式

见题面

样例输入
N = 3, M = 3 R = 1, C = 0 U = 1, D = 1 mat = {{'.', '.', '.'}, {'.', '#', '.'}, {'#', '.', '.'}}
样例输出
5