結果

問題 No.2582 Random Average^K
ユーザー chineristACchineristAC
提出日時 2023-12-10 00:10:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,650 ms / 2,000 ms
コード長 1,130 bytes
コンパイル時間 390 ms
コンパイル使用メモリ 81,996 KB
実行使用メモリ 322,720 KB
最終ジャッジ日時 2024-05-15 03:26:25
合計ジャッジ時間 25,589 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,159 ms
320,568 KB
testcase_01 AC 1,104 ms
320,428 KB
testcase_02 AC 1,104 ms
320,056 KB
testcase_03 AC 1,203 ms
320,220 KB
testcase_04 AC 1,106 ms
320,984 KB
testcase_05 AC 1,131 ms
320,240 KB
testcase_06 AC 1,134 ms
320,992 KB
testcase_07 AC 1,100 ms
321,960 KB
testcase_08 AC 1,134 ms
320,676 KB
testcase_09 AC 1,260 ms
321,452 KB
testcase_10 AC 1,330 ms
321,332 KB
testcase_11 AC 1,350 ms
320,716 KB
testcase_12 AC 1,650 ms
322,720 KB
testcase_13 AC 1,537 ms
322,420 KB
testcase_14 AC 1,111 ms
321,244 KB
testcase_15 AC 1,644 ms
321,960 KB
testcase_16 AC 1,371 ms
322,208 KB
testcase_17 AC 1,376 ms
321,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import permutations
from heapq import heappop,heappush
from collections import deque
import random
import bisect

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

"""
E[prod x_i^a_i] = prod 1/(ai+1)

sum a_i = K を満たすすべての a に対する
K! * prod 1/(ai+1)! の総和

1/1!+x/2!+x^2/3!+... = (e^x-1)/x

K! [x^K] (e^x-1)^N/x^N
= K! [x^(N+K)] (e^x-1)^N
"""

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    return (g1[n] * g2[r] % mod) * g2[n-r] % mod


mod = 998244353
N = 10**6 + 100 + 10**7
g1 = [1]*(N+1)
g2 = [1]*(N+1)
inverse = [1]*(N+1)

for i in range( 2, N + 1 ):
    g1[i]=( ( g1[i-1] * i ) % mod )
    inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2[i]=( (g2[i-1] * inverse[i]) % mod )
inverse[0]=0

N,K = mi()
res = 0
for i in range(N+1):
    if (N-i) & 1:
        res -= cmb(N,i,mod) * pow(i,N+K,mod) % mod
    else:
        res += cmb(N,i,mod) * pow(i,N+K,mod) % mod
    res %= mod

res *= g1[K] * g2[N+K] % mod
res %= mod

res *= pow(inverse[N],K,mod)
res %= mod

print(res % mod)
        
0