P2628 Adventure Island
Background
Adventure Island is a scenario-simulation computer game newly developed by Teacher Fei. By rolling a die (numbers 1 to 6), a character (the piece) walks from left to right on a board, thereby simulating an adventure story.
Description
On the board, there is a long road from left to right. The entire road is a sequence of symbols that describe the road’s state, and the piece must walk along this symbolic road. Each time you roll the die and obtain a number, the piece moves exactly that many steps. For example, if you roll a 3, it moves 3 steps.
There are two special symbols on the road that can change the piece’s movement:
- The “>” symbol: If, after finishing the steps from the die roll, the piece lands on this symbol and there are at least 2 consecutive “>” immediately following it, then the piece receives a forward bonus. It moves forward along the consecutive “>” one step at a time until it reaches a position whose symbol is not “>”, and stops there.
- The “\*” symbol: If, after finishing the steps from the die roll, the piece lands on this symbol and there are at least 2 consecutive “\*” immediately following it, then it suffers a backward penalty. It must move back by k steps, where k is the length of the consecutive “\*” run starting from the current “\*”.
After each roll, at most one bonus or penalty is applied. If, after applying a bonus or penalty, the piece lands on another special symbol, no further bonus or penalty is applied.
If the piece moves past the right boundary (beyond the last symbol), it stops at the last symbol. If it moves past the left boundary, it stops at the first symbol.
After several die rolls, determine which position the piece ends on, and how many steps remain to the end.
Input Format
- The first line is a string s, where each character describes the state of one position on the board.
- The second line is an integer n, the number of die rolls.
- The third line contains n integers (each in the range 1 to 6), the numbers obtained from the n rolls, separated by single spaces.
Output Format
Output exactly two numbers: the 1-based index of the current symbol and the number of steps remaining to the last symbol (inclusive). Separate them with a single space. Note: end the output with a newline.
Explanation/Hint
[Sample Explanation]
In the game, the first roll is 5, so the piece moves to the first “>” and gains a forward bonus to the second “f” from the left. The second roll is 6, so it lands on “\*”, suffers a penalty of 3 steps backward, and moves to “d”. The third roll is 6, so it reaches the fourth “>” from the left and gains a bonus to “f”. The piece finally stops at the 20th symbol (counting from left to right), and is 5 steps away from the last symbol “d” (inclusive).
Constraints
- For 50% of the testdata: 1