101971: [AtCoder]ABC197 B - Visibility

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $200$ points

Problem Statement

We have a grid of $H$ horizontal rows and $W$ vertical columns, where some of the squares contain obstacles.
Let $(i, j)$ denote the square at the $i$-th row from the top and $j$-th column from the left.
You are given $H$ strings $S_1, S_2, S_3, \dots, S_H$. The $j$-th character of $S_i$ describes the square $(i, j)$; # means the square contains an obstacle, and . means it does not.
We say a square is visible from another when it is on the same row or the same column, and there is no obstacle between them (including themselves).
Print the number of squares visible from the square $(X, Y)$ (including $(X, Y)$ itself).

Constraints

  • $1 \le H \le 100$
  • $1 \le W \le 100$
  • $1 \le X \le H$
  • $1 \le Y \le W$
  • $S_i$ is a string of length $W$ consisting of . and #.
  • The square $(X, Y)$ does not contain an obstacle.

Input

Input is given from Standard Input in the following format:

$H$ $W$ $X$ $Y$
$S_1$
$S_2$
$S_3$
$\hspace{3pt} \vdots$
$S_H$

Output

Print the answer.


Sample Input 1

4 4 2 2
##..
...#
#.#.
.#.#

Sample Output 1

4

The squares visible from the square $(2, 2)$ are:

  • $(2, 1)$
  • $(2, 2)$
  • $(2, 3)$
  • $(3, 2)$

Sample Input 2

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

Sample Output 2

4

Even if two squares are on the same row or the same column, they are not visible from each other when there are obstacles between them.


Sample Input 3

5 5 4 2
.#..#
#.###
##...
#..#.
#.###

Sample Output 3

3

Input

题意翻译

### 题目描述 我们有一个 $H$ 横行 $W$ 竖列的网格,其中有一些格是障碍。 我们约定 $(i, j)$ 为从上到下第 $i$ 行、从左到右第 $j$ 行的格。 给你 $H$ 个字符串 $S_1, S_2, S_3, \dots, S_H$。$S_i$ 的第 $j$ 个字符为格 $(i, j)$:`#` 表示是障碍格,`.` 表示不是障碍格。 当这个格和另一个格在同一行或者同一列上,并且它们两个之间没有障碍(包括它们自己)时,我们说这个格是 **可见的**。 输出在格 $(X, Y)$ 上 **可见的** 格数(包括它本身)。 ### 制约 - $1 \le H \le 100$ - $1 \le W \le 100$ - $1 \le X \le H$ - $1 \le Y \le W$ - $S_i$ 是一个长度为 $W$ 的字符串,且仅包含 `.` 和 `#`。 - 格 $(X, Y)$ 不是障碍格。 ### 输入 输入从标准输入(stdin)给出,并遵循以下格式: > $H\quad W\quad X\quad Y\\S_1\\S_2\\S_3\\\vdots\\S_H$ ### 输出 输出答案。 ### 样例解释 1 从格 $(2, 2)$ 可见的格有: - $(2, 1)$ - $(2, 2)$ - $(2, 3)$ - $(3, 2)$

加入题单

算法标签: