StonesGame
SRM 493 · 2010-11-01 · by maksay
Problem Statement
Constraints
- N will be between 2 and 1,000,000, inclusive.
- M, K and L will each be between 1 and N, inclusive.
- M and L will be different.
2 1 2 2 Returns: "Romeo"
3 1 1 2 Returns: "Draw"
There are three stones and the stone in position 1 is white. To win the game, a player must put the white stone in position 2. However, since K is 1, each player can only choose a single stone to reverse, so it is impossible to move the white stone from its original position. Therefore, neither player can win.
5 1 2 2 Returns: "Romeo"
Romeo can win on his first move by reversing the order of the first two stones.
5 5 2 3 Returns: "Strangelet"
Romeo's only possible move is to reverse the last two stones. This puts the white stone in position 4. Strangelet can then reverse the third and fourth stones, putting the white stone in position 3 and winning the game.
5 5 2 2 Returns: "Draw"
This is similar to the previous example, but here, the white stone must be moved to position 2. As in the previous example, Romeo's first move will put the white stone in position 4. This time, Strangelet will then move it back to position 5 because otherwise, Romeo would move it to position 2 and win. This sequence of moves will repeat infinitely and neither player will win.
Submissions are judged against all 193 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class StonesGame with a public method string winner(int N, int M, int K, int L) · 193 test cases · 2 s / 256 MB per case