結果

問題 No.2529 Treasure Hunter
ユーザー rlangevinrlangevin
提出日時 2023-11-03 22:15:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 81,808 KB
実行使用メモリ 76,520 KB
最終ジャッジ日時 2023-11-03 22:15:13
合計ジャッジ時間 2,387 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
59,996 KB
testcase_01 AC 142 ms
76,520 KB
testcase_02 AC 75 ms
75,860 KB
testcase_03 AC 71 ms
75,668 KB
testcase_04 AC 67 ms
73,604 KB
testcase_05 AC 69 ms
74,120 KB
testcase_06 AC 68 ms
73,428 KB
testcase_07 AC 76 ms
75,852 KB
testcase_08 AC 74 ms
75,844 KB
testcase_09 AC 64 ms
72,748 KB
testcase_10 AC 75 ms
75,844 KB
testcase_11 AC 73 ms
75,668 KB
testcase_12 AC 38 ms
53,556 KB
testcase_13 AC 38 ms
53,556 KB
testcase_14 AC 38 ms
53,556 KB
testcase_15 AC 37 ms
53,556 KB
testcase_16 AC 37 ms
53,556 KB
testcase_17 AC 38 ms
53,556 KB
testcase_18 AC 38 ms
53,556 KB
testcase_19 AC 38 ms
53,556 KB
testcase_20 AC 54 ms
53,556 KB
testcase_21 AC 38 ms
53,556 KB
testcase_22 AC 38 ms
53,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def Matprod(A, B, mod, N):
    temp = [0] * N*N
    for i in range(N):
        for j in range(N):
            ij = i * N + j
            for k in range(N):
                temp[ij] += A[i*N+k] * B[k*N+j]
                temp[ij] %= mod
    return temp

def Matpow_Linear(A, M, mod, N):
    Mat = [0] * N*N
    for i in range(N):
        Mat[i*N+i] = 1
         
    while M:
        if M & 1:
            Mat = Matprod(Mat, A, mod, N)
        A = Matprod(A, A, mod, N)
        M >>= 1
    return Mat  

T = int(input())
mod = 998244353
for _ in range(T):
    W, H = map(int, input().split())
    M = [1, 1, 1, W, W - 1, W - 2, max(0, W * (W - 3)//2), (W - 3) * (W - 2)//2, max(0, (W - 4) * (W - 3)//2 + 1)]
    M = Matpow_Linear(M, H, mod, 3)
    print( (M[0] + M[3] + M[6]) % mod )
0