Harvest Waterloo
Time limit1sMemory limit1024 MB
Given a grid of pumpkins and hay bales, the task sums the values of all pumpkins reachable by orthogonal moves from a start cell.
Problem
A new harvest simulation game, Harvest Waterloo, is wildly popular. The game is played on a rectangular pumpkin patch that contains bales of hay and pumpkins of different sizes. To begin, a farmer is placed on the location of a pumpkin.
The farmer harvests every pumpkin they can reach by moving left, right, up, and down. The farmer cannot move diagonally, cannot move through a bale of hay, and cannot move outside the patch.
A small pumpkin is worth $1, a medium pumpkin is worth $5, and a large pumpkin is worth $10. Determine the total value in dollars of all pumpkins the farmer harvests.
Input
The first line contains an integer (), the number of rows in the patch.
The second line contains an integer (), the number of columns in the patch.
The next lines describe the patch. Each line has characters. S is a small pumpkin, M is a medium pumpkin, L is a large pumpkin, and * is a bale of hay.
The next line contains an integer (), and the last line contains an integer (). Row and column is the farmer's starting location. The top-left corner of the patch is row 0, column 0.
Output
Output the integer , the total value in dollars of all pumpkins the farmer harvests.