#P10294. [CCC 2024 J5] Harvest Waterloo

    ID: 11619 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>搜索2024CCC(加拿大)广度优先搜索 BFS深度优先搜索 DFS

[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 11 dollar, a medium pumpkin is worth 55 dollars, and a large pumpkin is worth 1010 dollars.

Input Format

The first line of input is an integer R>0R > 0, the number of rows in the pumpkin field.

The second line is an integer C>0C > 0, the number of columns in the pumpkin field.

The next RR lines describe the entire pumpkin field. Each line contains CC 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 AA satisfying 0A<R0 \leq A < R, and the last line is an integer BB satisfying 0B<C0 \leq B < C, indicating that the farmer starts at row AA, column BB. The top-left corner of the pumpkin field is called row 00, column 00.

Output Format

Output an integer VV, 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 55, column 11, the farmer can harvest 66 pumpkins. The farmer can harvest 22 small pumpkins, 11 medium pumpkin, and 33 large pumpkins. The total value of the harvested pumpkins is 2×1+1×5+3×10=372 \times 1 + 1 \times 5 + 3 \times 10 = 37.

[Sample 2 Explanation]

Starting at row 22, column 44, the farmer can harvest 1919 pumpkins. The farmer can harvest 88 small pumpkins, 66 medium pumpkins, and 55 large pumpkins. The total value of the harvested pumpkins is 8×1+6×5+5×10=888 \times 1 + 6 \times 5 + 5 \times 10 = 88.

[Constraints]

This problem uses bundled testdata.

For all testdata, it is guaranteed that 1R,C1051 \leq R, C \leq 10^5 and 1R×C1051 \leq R \times C \leq 10^5.

The table below shows the 1515-point distribution:

Points Description Range
11 The pumpkin field is small and there is no hay. R×C100R \times C \leq 100
44 The pumpkin field is small and hay splits the field into some rectangular regions.
55 The pumpkin field is small and hay can be anywhere.
The pumpkin field may be large and hay can be anywhere. R×C105R \times C \leq 10^5

Translated by ChatGPT 5