結果

問題 No.2529 Treasure Hunter
ユーザー minimumminimum
提出日時 2023-11-03 21:53:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,601 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 81,828 KB
実行使用メモリ 100,236 KB
最終ジャッジ日時 2023-11-03 21:53:16
合計ジャッジ時間 6,569 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 162 ms
99,144 KB
testcase_01 WA -
testcase_02 AC 226 ms
100,020 KB
testcase_03 AC 262 ms
100,020 KB
testcase_04 AC 228 ms
99,404 KB
testcase_05 AC 235 ms
99,492 KB
testcase_06 AC 224 ms
99,492 KB
testcase_07 AC 230 ms
99,492 KB
testcase_08 WA -
testcase_09 AC 213 ms
99,152 KB
testcase_10 AC 228 ms
99,492 KB
testcase_11 AC 234 ms
99,528 KB
testcase_12 AC 212 ms
99,148 KB
testcase_13 AC 220 ms
99,144 KB
testcase_14 AC 230 ms
99,144 KB
testcase_15 AC 209 ms
99,144 KB
testcase_16 AC 207 ms
99,144 KB
testcase_17 AC 204 ms
99,148 KB
testcase_18 AC 204 ms
99,148 KB
testcase_19 AC 202 ms
99,144 KB
testcase_20 AC 227 ms
99,144 KB
testcase_21 AC 206 ms
99,144 KB
testcase_22 AC 206 ms
99,148 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())
    c2 = com.c(N - 2, 2)

    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)
        if N >= 3:
            ndp[1] += dp[2] * (N - 2)
            ndp[1] += dp[1] * (N - 1)
            ndp[1] += dp[0] * N
        if N >= 2:
            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