結果

問題 No.2132 1 or X Game
ユーザー roarisroaris
提出日時 2022-11-25 23:50:10
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,689 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 82,856 KB
実行使用メモリ 279,164 KB
最終ジャッジ日時 2024-04-10 04:49:22
合計ジャッジ時間 7,362 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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()

def f(N):
    res = 0
    for i in range(1, N+1):
        if grundy(i, 0, 1, 1)>=1:
            res += 1
    return res

MOD = 998244353

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