Simulate a snake that grows on checkerboard food on a wrapping board with timed turns and report its length after death or one billion steps.
Medium7SimulationQueueHash mapMathNo attempts yetTime limit5sMemory limit512 MBAlex likes the Snake game. He has just learned to program and wants to build his own version with the following rules.
Simulate the list of turn actions Alex wrote down and report the length of the snake when the game is over. The game ends either because the head overlaps another cell of the snake after a move is complete, or because the time limit passes. In the first case, count the head and the overlapping body cell as two separate cells when measuring the length.
The first line contains the number of test cases T. T test cases follow.
The first line of each test case contains three integers S, R, and C. S is the number of turn actions, and R and C are the number of rows and columns of the board. Each of the next S lines contains an integer Xi and a character Ai, where Ai is L or R. That line means action Ai is performed between second Xi and second Xi+1.
The actions are given in increasing order of time, and there is never more than one action between the same two seconds. The game may end before the snake performs all of the actions.
For each test case, print one line in the form Case #x: y, where x is the test case number starting from 1 and y is the length of the snake when the game is over.