結果

問題 No.2529 Treasure Hunter
ユーザー minimumminimum
提出日時 2023-11-03 21:58:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 313 ms / 2,000 ms
コード長 1,522 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 81,888 KB
実行使用メモリ 100,332 KB
最終ジャッジ日時 2023-11-03 21:59:02
合計ジャッジ時間 6,909 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 176 ms
99,096 KB
testcase_01 AC 313 ms
100,332 KB
testcase_02 AC 252 ms
99,712 KB
testcase_03 AC 260 ms
95,624 KB
testcase_04 AC 289 ms
98,732 KB
testcase_05 AC 257 ms
99,384 KB
testcase_06 AC 255 ms
99,384 KB
testcase_07 AC 264 ms
99,384 KB
testcase_08 AC 268 ms
99,384 KB
testcase_09 AC 239 ms
99,036 KB
testcase_10 AC 260 ms
99,384 KB
testcase_11 AC 270 ms
99,404 KB
testcase_12 AC 234 ms
99,032 KB
testcase_13 AC 238 ms
99,032 KB
testcase_14 AC 232 ms
99,032 KB
testcase_15 AC 229 ms
99,028 KB
testcase_16 AC 236 ms
99,032 KB
testcase_17 AC 232 ms
99,032 KB
testcase_18 AC 251 ms
99,028 KB
testcase_19 AC 232 ms
99,032 KB
testcase_20 AC 233 ms
99,032 KB
testcase_21 AC 237 ms
99,032 KB
testcase_22 AC 234 ms
99,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Combination:

    def __init__(self, MX=10**6, MOD=998244353):
        self.MX = MX
        self.MOD = MOD
        self.fact = [1] * (MX + 1)
        self.inv = [1] * (MX + 1)
        self.f_inv = [1] * (MX + 1)
        for i in range(2, MX + 1):
            self.fact[i] = (self.fact[i - 1] * i) % self.MOD
            self.inv[i] = ( - (self.MOD // i) * (self.inv[self.MOD % i])) % self.MOD
            self.f_inv[i] = (self.f_inv[i - 1] * self.inv[i]) % self.MOD
    
    def invs(self, n):
        if n <= self.MX:
            return self.inv[n]
        else:
            return pow(n, self.MOD - 2, self.MOD)
    
    def p(self, n, r):
        if r > n or r < 0:
            return 0
        return (self.fact[n] * self.f_inv[r]) % self.MOD
    
    def c(self, n, r):
        if r > n or r < 0:
            return 0
        return (self.fact[n] * self.f_inv[r] * self.f_inv[n - r]) % self.MOD

MOD = 998244353
com = Combination()

def solve():
    N, M = map(int, input().split())

    dp = [1, 0, 0]
    for i in range(M):
        ndp = [0, 0, 0]
        if N >= 4:
            ndp[2] += dp[2] * (com.c(N - 2, 2) - (N - 4))
            ndp[2] += dp[1] * (com.c(N - 1, 2) - (N - 2))
            ndp[2] += dp[0] * (com.c(N, 2) - N)
        ndp[1] += dp[2] * (N - 2)
        ndp[1] += dp[1] * (N - 1)
        ndp[1] += dp[0] * N
        ndp[0] += sum(dp)
        ndp[0] %= MOD
        ndp[1] %= MOD
        ndp[2] %= MOD
        dp = ndp
    print(sum(dp) % MOD)

T = int(input())
for _ in range(T):
    solve()
0