题目描述
Problem Description
There is a grid consisting of 9 rows and 9 columns, and the cell at the i-th row from the top and the j-th column from the left is represented as (i,j).
Initially, a piece is placed on the cell (A,B), and no other cells have pieces.
The piece can move in one step to some of the 8 neighboring cells of the cell it is currently on. The specific set of cells it can move to is represented by three strings \( S_1, S_2, S_3 \) each of length 3. When the piece is on the cell (x,y),
- If the j-th character of \( S_i \) is
#, it can move to the cell \( (x+i-2, y+j-2) \) in one step. - If the j-th character of \( S_i \) is
., it cannot move to the cell \( (x+i-2, y+j-2) \) in one step.
However, moving outside the grid is not allowed.
Find the number of cells that the piece can reach through zero or more moves.
Input Format
The input is given from the standard input in the following format:
\( A \) \( B \) \( S_1 \) \( S_2 \) \( S_3 \)
Output Format
Output the number of cells that the piece can reach through zero or more moves.
Sample Input and Output
Sample Input #1
2 2
###
#..
...
Sample Output #1
5
Sample Input #2
5 4
###
#.#
###
Sample Output #2
81
Sample Input #3
9 9
...
...
..#
Sample Output #3
1
Notes/Hints
Constraints
- \( 1 \leq A, B \leq 9 \)
- \( S_1, S_2, S_3 \) are strings of length 3 consisting only of
#and. - The 2nd character of \( S_2 \) is
. - \( A, B \) are integers
Sample Explanation 1
The piece can reach a total of 5 cells: (1,1), (1,2), (1,3), (2,1), and (2,2).
Sample Explanation 2
The piece can reach all cells.
Sample Explanation 3
The piece cannot move from the initial cell (9,9) to any other cell.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分