#P10294. [CCC 2024 J5] Harvest Waterloo
[CCC 2024 J5] Harvest Waterloo
Problem Description
A new and popular harvesting simulation game called Harvest Waterloo has appeared. The game is played on a rectangular pumpkin field. In the field, there are bundles of hay and pumpkins of different sizes. At the start of the game, a farmer is standing on the position of one of the pumpkins.
The farmer harvests pumpkins by moving across the field left, right, up, or down. 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 the farmer can harvest. A small pumpkin is worth dollar, a medium pumpkin is worth dollars, and a large pumpkin is worth dollars.
Input Format
The first line of input is an integer , the number of rows in the pumpkin field.
The second line is an integer , the number of columns in the pumpkin field.
The next lines describe the entire pumpkin field. Each line contains characters, and each character represents either a pumpkin or hay: S represents a small pumpkin, M represents a medium pumpkin, L represents a large pumpkin, and * represents hay.
The next line contains an integer satisfying , and the last line is an integer satisfying , indicating that the farmer starts at row , column . The top-left corner of the pumpkin field is called row , column .
Output Format
Output an integer , the total value of the pumpkins that the farmer can harvest.
6
6
**LMLS
S*LMMS
S*SMSM
******
LLM*MS
SSL*SS
5
1
37
6
6
**LMLS
S*LMMS
S*SMSM
***SLL
LLM*MS
SSL*SS
2
4
88
Hint
[Sample 1 Explanation]

Starting at row , column , the farmer can harvest pumpkins. The farmer can harvest small pumpkins, medium pumpkin, and large pumpkins. The total value of the harvested pumpkins is .
[Sample 2 Explanation]

Starting at row , column , the farmer can harvest pumpkins. The farmer can harvest small pumpkins, medium pumpkins, and large pumpkins. The total value of the harvested pumpkins is .
[Constraints]
This problem uses bundled testdata.
For all testdata, it is guaranteed that and .
The table below shows the -point distribution:
| Points | Description | Range |
|---|---|---|
| The pumpkin field is small and there is no hay. | ||
| The pumpkin field is small and hay splits the field into some rectangular regions. | ||
| The pumpkin field is small and hay can be anywhere. | ||
| The pumpkin field may be large and hay can be anywhere. |
Translated by ChatGPT 5