Brue Marble
Time limit3sMemory limit1024 MB
Given a grid of arrows and timed point events, find the score after L moves from a start cell, applying events as they are added.
- Level
Hard8 of 10
- Topics
- Graph, Dynamic programming, Tree
- Solved
- No attempts yet
Problem
Brue Marble is a game where you move the hero Brue across a board so that Brue can join events held at different places on the board. The board is a grid of rows and columns. Each cell has an arrow pointing in one of 8 directions: up, down, left, right, or one of the four diagonals. The cell in the direction each arrow points to always exists.
An event lasts for exactly one turn. If the player is on the event's cell during that turn, the player can join the event and earn points. The points for each event are set by that event.
The game runs as follows.
- Before the game starts, choose a starting cell and place the piece on it.
- Repeat the following turn times. Each turn works like this:
- First, move one cell in the direction the arrow on the current cell points.
- If an event is open on the new cell, the player earns the points for that event. If several events are open there, the player earns the sum of their points.
- After turns, compute the final score.
Most of the game is finished, but the events have not been decided yet. You are a beta tester and need to simulate the game to check whether its balance is right. You must compute the final score when a given cell is the starting cell. Events may be added during the process, and you must reflect each addition. No events are scheduled at the start.
You must handle the following two kinds of tasks. Write cell for row and column .
- Add an event: add an event that opens at cell during turn . Joining this event earns points.
- Compute the score: compute the final score when the piece starts at cell .
Input
The first line contains two integers and , the size of the grid, and two integers and , the number of turns and the number of tasks.
The next lines describe the arrows. Line contains characters, and character is the arrow in row , column . Row numbers increase from top to bottom and column numbers increase from left to right. The characters mean the following directions.
Q: up-leftW: upE: up-rightD: rightC: down-rightX: downZ: down-leftA: left
The next lines each describe one task, in one of these formats.
- : add an event that opens at during turn . Joining it earns points.
- : compute the final score when the piece starts at .
Output
For each score computation task, print the final score on its own line.
Constraints
- for and
- For an add-event task: , , , .
- For a score computation task: and .
- There is at least one score computation task.
- Every arrow points to a cell that exists on the board.