Rock Paper Scissors Lizard Spock
Time limit1sMemory limit256 MB
Leo recovers the computer's hidden move generator from n observed throws and prints the winning reply to each of the next m throws.
- Level
Medium5 of 10
- Topics
- Brute force, Math, Simulation
- Solved
- No attempts yet
Problem
Leo plays rock, paper, scissors, lizard, Spock against his computer. The game runs in rounds, and in every round the two players pick one of five options at the same time: rock, paper, scissors, lizard, Spock. Each option beats exactly two of the other four.
If both players pick the same option, the round is a draw.

Figure F.1: the mechanics of the game. Illustration by VidTheKid via Wikimedia Commons.
Leo's computer picks its option with a linear congruential generator. The generator uses a known prime and two fixed integers and that Leo does not know. It also keeps a state whose starting value Leo does not know either. Before every round the computer updates the state,
and then reads its option out of this table.
Leo watched the first rounds and wrote down everything the computer played. He wants to win every one of the next rounds. Two options beat any given option, and Leo always takes the one that comes first in the order rock, paper, scissors, lizard, Spock.
Print what Leo plays in each of the next rounds.
Input
The first line has two integers and (, ).
Each of the next lines holds one of the words rock, paper, scissors, lizard, Spock: what the computer played in that round, in order.
The recorded rounds come from a generator of the form above, and they determine the next options. Every triple that reproduces all recorded options produces the same options after them.
Output
Print lines. Line holds what Leo plays in round : the option that beats the computer's choice in that round, and when two options beat it, the one that comes first in the order rock, paper, scissors, lizard, Spock.