結果

問題 No.2582 Random Average^K
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-12-10 13:34:20
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,029 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 549,056 KB
最終ジャッジ日時 2023-12-10 13:34:31
合計ジャッジ時間 9,518 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,460 KB
testcase_01 AC 34 ms
53,460 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 36 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 63 ms
72,516 KB
testcase_07 AC 49 ms
64,208 KB
testcase_08 AC 66 ms
72,504 KB
testcase_09 AC 1,045 ms
260,468 KB
testcase_10 TLE -
testcase_11 AC 1,736 ms
366,212 KB
testcase_12 MLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K = map(int,input().split())
mod = 998244353

class combination():

    def __init__(self,N,p):
        
        
        self.fact = [1, 1]  # fact[n] = (n! mod p)
        self.factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
        self.inv = [0, 1]  # factinv 計算用
        self.p = p
        
        for i in range(2, N + 1):
            self.fact.append((self.fact[-1] * i) % p)
            self.inv.append((-self.inv[p % i] * (p // i)) % p)
            self.factinv.append((self.factinv[-1] * self.inv[-1]) % p)
        

    def cmb(self,n, r):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return self.fact[n] * self.factinv[r] * self.factinv[n-r] % self.p
    
C = combination(K+1+N,mod)

ans = 0
for i in range(N):

    if i%2==0:

        ans = (ans + C.cmb(N,i)*pow(N-i,N+K,mod))%mod
    else:
        ans = (ans - C.cmb(N,i)*pow(N-i,N+K,mod))%mod

inv = pow(C.fact[N+K]*C.factinv[K],mod-2,mod)
ans = (ans*inv)%mod
inv = pow(pow(N,K,mod),mod-2,mod)
print(ans*inv%mod)
0