結果

問題 No.1403 調和の魔法陣
ユーザー lam6er
提出日時 2025-03-26 15:57:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,638 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 82,636 KB
実行使用メモリ 77,908 KB
最終ジャッジ日時 2025-03-26 15:58:06
合計ジャッジ時間 3,431 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

# Precompute four variables sum (for H=2, W=2 case)
max_four = 4 * 9
four_dp = [0] * (max_four + 1)
four_dp[0] = 1
for _ in range(4):
    new_dp = [0] * (len(four_dp) + 9)
    for s in range(len(four_dp)):
        if four_dp[s] == 0:
            continue
        for k in range(10):
            new_dp[s + k] = (new_dp[s + k] + four_dp[s]) % MOD
    four_dp = new_dp[:max_four + 1]

T = int(input())
for _ in range(T):
    W, H, X = map(int, input().split())
    # Determine the case
    if H >= 3 and W >= 3:
        print(1 if X == 0 else 0)
    elif H == 1 or W == 1:
        if (H == 1 and W == 1) or (W == 1 and H == 1):
            print(1 if 0 <= X <= 9 else 0)
        else:
            if H == 1:
                K = W
            else:
                K = H
            if K == 2:
                if X < 0 or X > 18:
                    print(0)
                else:
                    if X <= 9:
                        print((X + 1) % MOD)
                    else:
                        print((19 - X) % MOD)
            else:
                print(1 if 0 <= X <=9 else 0)
    elif H == 2 and W == 2:
        if X < 0 or X > 36:
            print(0)
        else:
            print(four_dp[X] % MOD)
    elif (H == 2 and W >= 2) or (W == 2 and H >= 2):
        max_X = 6 * 9  # 54
        if X < 0 or X > max_X:
            print(0)
        else:
            total = 0
            for s in range(0, X + 1):
                term = pow(s + 1, 2, MOD) * pow(X - s + 1, 2, MOD)
                term %= MOD
                total = (total + term) % MOD
            print(total % MOD)
    else:
        print(0)
0