题目描述
Problem Description
A new and popular harvesting simulation game called Harvest Waterloo has emerged. The game takes place on a rectangular pumpkin field, which contains bundles of hay and pumpkins of various sizes. At the start of the game, a farmer is positioned at one of the pumpkin locations.
The farmer harvests pumpkins by moving left, right, up, or down across the field. The farmer cannot move diagonally, cannot pass through hay, and cannot leave the field.
Your task is to determine the total value of the pumpkins harvested by the farmer. A small pumpkin is worth $1, a medium-sized pumpkin is worth $5, and a large pumpkin is worth $10.
Input Format
The first line of input is an integer $R > 0$ representing the number of rows in the pumpkin field.
The second line is an integer $C > 0$ representing the number of columns in the pumpkin field.
The next $R$ lines describe the entire pumpkin field. Each line contains $C$ characters, where each character represents either a pumpkin or hay: S for a small pumpkin, M for a medium-sized pumpkin, L for a large pumpkin, and * for hay.
The next line contains an integer $A$ where $0 \leq A < R$, and the last line is an integer $B$ where $0 \leq B < C$. These represent the starting position of the farmer at the $A$-th row and $B$-th column. The top-left corner of the field is considered the $0$-th row and $0$-th column.
Output Format
Output an integer $V$ representing the total value of the pumpkins that the farmer can harvest.
Sample Input and Output
Sample Input #1
6
6
**LMLS
S*LMMS
S*SMSM
******
LLM*MS
SSL*SS
5
1
Sample Output #1
37
Sample Input #2
6
6
**LMLS
S*LMMS
S*SMSM
***SLL
LLM*MS
SSL*SS
2
4
Sample Output #2
88
Notes
[Sample 1 Explanation]
The farmer starts at the $5$-th row and $1$-th column and can harvest $6$ pumpkins. These include $2$ small pumpkins, $1$ medium-sized pumpkin, and $3$ large pumpkins. The total value of the harvested pumpkins is $2 \times 1 + 1 \times 5 + 3 \times 10 = 37$.
[Sample 2 Explanation]
The farmer starts at the $2$-th row and $4$-th column and can harvest $19$ pumpkins. These include $8$ small pumpkins, $6$ medium-sized pumpkins, and $5$ large pumpkins. The total value of the harvested pumpkins is $8 \times 1 + 6 \times 5 + 5 \times 10 = 88$.
[Data Range]
This problem uses bundled testing.
For all data, it is guaranteed that $1 \leq R, C \leq 10^5$ and $1 \leq R \times C \leq 10^5$.
The following table shows the distribution of $15$ points:
| Points | Description | Range |
|---|---|---|
| $1$ | The pumpkin field is small and there is no hay. | $R \times C \leq 100$ |
| $4$ | The pumpkin field is small and hay divides the field into rectangular regions. | $R \times C \leq 100$ |
| $5$ | The pumpkin field is small and hay can be at any position. | $R \times C \leq 100$ |
| $5$ | The pumpkin field can be large and hay can be at any position. | $R \times C \leq 10^5$ |
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分