結果

問題 No.2132 1 or X Game
ユーザー roarisroaris
提出日時 2022-11-25 23:35:40
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,468 bytes
コンパイル時間 420 ms
コンパイル使用メモリ 86,908 KB
実行使用メモリ 78,484 KB
最終ジャッジ日時 2023-07-25 11:43:52
合計ジャッジ時間 4,919 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,652 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

def grundy(c, t, f1, f2):
    if memo[c][t][f1][f2]!=-1:
        return memo[c][t][f1][f2]
    
    if c==0:
        return 0
    
    s = set()
    
    if t==0:
        s.add(grundy(c-1, 1^t, 1, f2))
        
        if c-X>=0 and f1==1:
            s.add(grundy(c-X, 1^t, 0, f2))
    else:
        s.add(grundy(c-1, 1^t, f1, 1))
        
        if c-X>=0 and f2==1:
            s.add(grundy(c-X, 1^t, f1, 0))
    
    res = 0
    
    while res in s:
        res += 1
    
    memo[c][t][f1][f2] = res
    return res

# for X in range(100):
#     print('X:', X, '|', end=' ')
#     memo = [[[[-1]*2 for _ in range(2)] for _ in range(2)] for _ in range(110)]
#     acc = 0
#     for N in range(100):
#         g = grundy(N, 0, 1, 1)
#         # print(1 if g>=1 else 0, end=' ')
        
#         if X%2==0:
#             if g>=1:
#                 acc += 1
#             print(acc, end=' ')
        
#     print()

MOD = 998244353

for _ in range(int(input())):
    N, X = map(int, input().split())
    
    if X%2==1:
        ans = (N-N//2)%MOD
        print(ans)
    else:
        s = X//2
        d = 2+X//2
        
        if N<s:
            ans = (N+1)//2%MOD
        else:
            if N%2==0:
                ans = (N+1)//2+(N-s+1)//d//2
                ans %= MOD
            else:
                ans = (N+1)//2+(N-s+1)//d//2-1
                ans %= MOD
            
        print(ans)
0