Number Game
Time limit1sMemory limit128 MB
With Ellie's responses fixed by a1..a20, decide if the first player can force reaching 0 in a subtraction game.
- Level
Medium6 of 10
- Topics
- Game theory, Dynamic programming, Implementation
- Solved
- No attempts yet
Problem
Carl and Ellie are on a road trip across Canada. They have just arrived in Saskatchewan, right in the middle of the Canadian prairies, and have discovered that all the rumours about it being dreadfully flat are true:
It's so flat, a boy can watch his dog run away!
It's so flat, it's impossible to jump to your death!
To fight off boredom at the wheel, Carl invents a simple game with the following rules:
- Carl picks an integer with .
- Carl and Ellie take turns subtracting an integer between and from the current number. Carl moves first, and the player who subtracts to reach exactly wins.
For example, suppose Carl picks . He subtracts , leaving ; Ellie subtracts , leaving ; Carl subtracts , leaving ; finally Ellie subtracts , reaching and winning. (This only illustrates the moves; it is not Ellie's fixed strategy described below.)
Ellie would rather sleep than play, so she reprograms the GPS to choose for her. Its rule is:
- On Ellie's turn, if the current number is or less, she subtracts all of it and wins immediately.
- Otherwise (the current number exceeds ), her move is completely determined by Carl's last move. Before the game, Ellie fixes twenty numbers with . Whenever Carl subtracts , Ellie subtracts .
Given and , determine whether Carl has a strategy that guarantees a win.
Input
The input consists of several test cases. Each test case has on its own line, followed by a line with separated by spaces. Input terminates with a line containing a single .
Constraints: and .
Output
For each test case, print Carl can win if Carl has a winning strategy, or Carl can't win otherwise, each on its own line.
Hint
When and , Carl has no winning strategy: whatever number he subtracts first, Ellie subtracts , always leaving . Then whatever Carl subtracts next leaves a value between and , and Ellie wins.