2015-16 Woburn Challenge Finals - Senior Division
With intel from the Sacred Tree stolen by hydrated bovine spies, times are getting ever more desperate for the monkeys. The Head-Monkey has decided it's time to send out her own elite special agent – Agent Tiny. Tiny has been ordered to journey to Old MacDonald's farm and perform a precision strike against the cows' military headquarters. For this extremely dangerous mission, Tiny is being outfitted with a sophisticated piece of monkey technology – a fully functional car made of branches and leaves, and powered by banana juice. This car will offer him more than enough speed and maneuverability to infiltrate the barn. Also, it can shoot missiles from its front headlights.
In an effort to ensure that Tiny actually accomplishes something useful
with his car in the field, the Head-Monkey has instructed him to take it
for a spin on the monkeys' specialized driving course. The course will
take place in a very large room, which can be represented as a 2D grid
of cells, with some targets on the walls. The rows are numbered in
increasing order from North to South (starting from
Tiny will start in the Northwestern-most cell (in the first row and
first column), with his car facing South. Each second, he may either
drive to an adjacent cell, or fire a missile in the direction that his
car is currently facing. If he chooses to drive, he may do so in one of
the four cardinal directions (North, South, East, or West) as long as he
stays within the room (he can't drive North from row
The Head-Monkey will add
The R
or C
) and an integer R
, then the C
, then the
To help convince the Head-Monkey of Tiny's driving skills, can you help
Tiny determine how quickly the course can be completed each of the
In test cases worth
In test cases worth another
Input Specification
The first line of input consists of a single integer
The next
Output Specification
Output
Sample Input 1
3
R 3
C 2
C 3
Sample Output 1
4
6
8
Sample Explanation 1
The third and final time that Tiny completes the course, one optimal sequence of actions that he can take is as follows:
- Drive East
- Drive South
- Fire a missile (hitting target
) - Drive East
- Drive South
- Fire a missile (hitting target
) - Drive East
- Fire a missile (hitting target
)
Sample Input 2
2
R 1
R 10
Sample Output 2
2
13
Comments