Coin Toss Game
Time limit1sMemory limit256 MB
Given K rounds of a turn-taking coin game that stops once the result is settled, decide for each query whether the score pair can be the final score.
- Level
Medium6 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Younghee and Dongsu play a coin toss game. The game runs for rounds under these rules.
- In one round each player tosses a coin once, and Younghee always tosses first.
- A head scores 1 point and a tail scores nothing.
- After every single toss the players check whether the result is already settled. If one player would stay below the opponent's current score even after getting a head on every toss they have left, the game stops right there, even in the middle of a round.
Let be Younghee's score and be Dongsu's score at the moment the game stops. Picking any two integers and between and does not give a pair that a game can actually produce. For , the nine pairs split like this.
Here is why is impossible. Dongsu needs a head in both rounds to reach 2 points, so he already holds 1 point when the second round starts. Younghee has to toss a tail to stay at 0 points, and at that moment she has no tosses left, so she can never pass Dongsu. Rule 3 stops the game at 0 and 1, and Dongsu never tosses his second coin.
Given and , decide whether the two numbers can be Younghee's and Dongsu's scores once the game has ended.
Input
The first line has the number of rounds ().
The second line has the number of queries ().
Each of the next lines has two integers and separated by a space ().
Output
Print lines. On the -th line print 1 if the and of the -th query can be the scores of Younghee and Dongsu once the game has ended, and 0 otherwise.