結果

問題 No.2529 Treasure Hunter
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-11-04 12:09:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 648 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 81,876 KB
実行使用メモリ 76,344 KB
最終ジャッジ日時 2023-11-04 12:09:13
合計ジャッジ時間 3,992 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
62,140 KB
testcase_01 AC 131 ms
76,344 KB
testcase_02 AC 77 ms
75,728 KB
testcase_03 AC 82 ms
75,732 KB
testcase_04 AC 79 ms
75,732 KB
testcase_05 AC 76 ms
75,444 KB
testcase_06 AC 78 ms
75,448 KB
testcase_07 AC 83 ms
75,776 KB
testcase_08 AC 82 ms
75,460 KB
testcase_09 AC 68 ms
75,392 KB
testcase_10 AC 80 ms
75,728 KB
testcase_11 AC 80 ms
75,724 KB
testcase_12 AC 124 ms
75,772 KB
testcase_13 AC 127 ms
75,924 KB
testcase_14 AC 118 ms
75,688 KB
testcase_15 AC 122 ms
75,772 KB
testcase_16 AC 121 ms
75,748 KB
testcase_17 AC 123 ms
75,772 KB
testcase_18 AC 120 ms
75,772 KB
testcase_19 AC 120 ms
75,748 KB
testcase_20 AC 116 ms
75,724 KB
testcase_21 AC 121 ms
75,744 KB
testcase_22 AC 125 ms
75,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353

def solve():
    n,m = map(int,input().split())

    dp = [1,0,0]

    for i in range(m):

        ndp = [0]*3

        for bi in range(3):

            rest = n-bi
            if rest < 0:
                continue

            ndp[0] += dp[bi]
            ndp[0] %= mod

            if rest == 0:
                continue

            ndp[1] += dp[bi] * rest
            ndp[1] %= mod

            if rest == 1 or n < 4:
                continue

            ndp[2] += (rest*(rest-1)//2 - (n-2*bi)) * dp[bi]
            ndp[2] %= mod

        dp = ndp

    return sum(dp)%mod
t = int(input())
for _ in range(t):
    print(solve())
0