結果

問題 No.2529 Treasure Hunter
コンテスト
ユーザー aaaaaaaaaa2230
提出日時 2023-11-04 12:09:09
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 648 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 129 ms
コンパイル使用メモリ 84,992 KB
実行使用メモリ 81,536 KB
最終ジャッジ日時 2026-04-13 01:16:35
合計ジャッジ時間 2,813 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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