#P5006. Journey through the Mechanized Maze

    ID: 18244 Type: Default 1000ms 256MiB

Journey through the Mechanized Maze

Journey through the Mechanized Maze

Fusu is exploring a mechanized underground maze in Chang'an City. The maze is represented by an \(n \times m\) grid. Each cell in the grid contains one of three potions or a monster, indicated by the characters R, Q, Y, and M.

The potions have the following effects:

  • R: Life Potion - Reduces the lost HP by 10. If the lost HP is less than or equal to 10, it becomes 0.
  • Q: Strength Potion - Increases Fusu's attack (\(ST\)) by 5.
  • Y: Defense Potion - Increases Fusu's defense (\(DE\)) by 5.

The monster, represented by M, always appears with the same attributes: \(HP_0\), \(ST_0\), and \(DE_0\). Whenever Fusu steps into a cell containing a monster, a battle occurs. Although Fusu always defeats the monster, he loses HP as calculated by the formula below:

\(\text{damage} = \max\Bigl(1, \left\lceil \frac{HP_0}{\max(1, ST - DE_0)} \right\rceil \times \max(1, ST_0 - DE)\Bigr)\)

Note that if Fusu re-enters a cell, the cell's contents are reset, meaning that potions are picked up again or the monster appears again.

Fusu will perform \(q\) operations. Each operation is one of the following:

  • Move: Represented by M d, where \(d\) is one of {1, 2, 3, 4} corresponding to a movement in the left, right, up, and down directions respectively. Moving up decreases the row index by 1, down increases it by 1, left decreases the column index by 1, and right increases it by 1.
  • Query: Represented by Q. When a query is encountered, you should output Fusu's current total lost HP, attack (\(ST\)), and defense (\(DE\)), separated by spaces.

The initial cell (starting position) does not trigger any effect even if it contains a potion or a monster.

inputFormat

The input format is as follows:

  1. The first line contains two integers \(n\) and \(m\), representing the dimensions of the grid.
  2. The next \(n\) lines each contain a string of \(m\) characters. Each character is one of R, Q, Y, or M, representing the content of that cell.
  3. The following line contains two integers \(r\) and \(c\) (1-indexed), representing Fusu's starting position.
  4. The next line contains three integers: \(HP_0\), \(ST_0\), and \(DE_0\) for the monster's attributes.
  5. The next line contains an integer \(q\), the number of operations.
  6. The following \(q\) lines each describe an operation. An operation is either:
    • Q indicating a query operation, or
    • M d indicating a move operation, where \(d\) is one of 1 (left), 2 (right), 3 (up), or 4 (down).

outputFormat

For each query operation, output a single line containing three integers: the total lost HP, the current attack (\(ST\)), and the current defense (\(DE\)) of Fusu, separated by spaces.

sample

3 3
RQM
YYY
MQR
2 2
30 10 5
5
Q
M 1
Q
M 3
Q
0 0 0

0 0 5 0 0 5

</p>