Kaosar And Game#12261

Kaosar And Game (Editorial)

Problem Author:

AlKaosar Hussain

Prepared by:

Hasan Saleh (MathModel)

Edited by:

Hasan Saleh (MathModel)

Solution

View a fake jump as a personal pass: it consumes from your budget (you have , Kaosar has ) and leaves the robot on the same stair, merely handing the turn to the opponent. First strip passes away and recall the base fact for the "take " game: the player to move loses exactly on stair counts that are multiples of (k+1), and otherwise wins by moving to the nearest lower multiple of (k+1).

Now reintroduce passes. Passing is only rational when you are facing a losing base position (a multiple of (k+1)): if you are on a winning base position, you should immediately move to a losing one for your opponent; giving away the move gains nothing. Consequently, whenever a losing base position occurs, both players want to pass; these passes consume the two budgets symmetrically until one side runs out first. If p=q, every time a losing base position appears the two passes neutralize each other in pairs, and we fall back to the base game: the player to move from that position is the same as without passes, so the overall outcome is exactly the base rule, namely you lose iff n \bmod (k+1)=0.

If p\neq q, the side with the larger budget can always ensure that the other player is the first who must actually move from a losing base position: each time such a position appears, both attempt to pass; after \min(p,q) such standoffs, the smaller budget is exhausted one step earlier, and at the next losing base position that player is forced to move. Once the opponent is the one who must move from a losing base position, you resume the base winning strategy (always move to the nearest lower multiple of (k+1) on your turns) and no further passes are necessary. Therefore, if p>q you win for all ; if p<q you lose for all ; and if p=q the game reduces to the base case with the usual condition on n \bmod (k+1).

Complexity


for _ in range(int(input())):
   n,k,p,q = map(int,input().split())
   if p>q:
      print("yes")
   elif p == q:
      if n%(k+1)==0:
         print("no")
      else:
         print("yes")
   else:
      print("no")