Two Button-Pressing Robots
Time limit5sMemory limit512 MB
Two robots starting at button 1 share one ordered press sequence and move or press each second, so compute the minimum time to finish it.
- Level
Easy3 of 10
- Topics
- Simulation, Greedy
- Solved
- No attempts yet
Problem
Orange and Blue are friendly robots. An evil computer has locked them into separate hallways to test them, and it might give them cake afterwards.
Each hallway holds 100 buttons numbered 1 to 100. Button sits meters from the start of the hallway, and both robots start at button 1. In one second a robot walks one meter in either direction, presses the button at its own position once, or stays where it is and does nothing. To pass the test, the robots must press a given sequence of buttons in the given order. Both robots know the whole sequence in advance. Find the minimum time the two robots need to finish the sequence.
For example, suppose the sequence is O 2, B 1, B 2, O 4. Here O 2 means button 2 in Orange's hallway and B 1 means button 1 in Blue's hallway. The robots can finish this sequence in 6 seconds with the strategy below.
Time | Orange | Blue
-----+------------------+------------------
1 | Move to button 2 | Stay at button 1
2 | Push button 2 | Stay at button 1
3 | Move to button 3 | Push button 1
4 | Move to button 4 | Move to button 2
5 | Stay at button 4 | Push button 2
6 | Push button 4 | Stay at button 2
Blue has to wait until Orange has finished pressing O 2 before it can press B 1.
Input
The first line holds the number of test cases . test cases follow.
Each test case is a single line. The line starts with the number of buttons to press, , followed by terms of the form . is a robot color, always O or B, and is a button number.
Limits
- for all
Output
For each test case, print one line of the form Case #x: y, where is the test case number starting from 1 and is the minimum number of seconds the robots need to press the given buttons in order.