結果

問題 No.2582 Random Average^K
ユーザー chineristACchineristAC
提出日時 2023-12-10 00:10:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,797 ms / 2,000 ms
コード長 1,130 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 320,432 KB
最終ジャッジ日時 2023-12-14 16:46:17
合計ジャッジ時間 27,677 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,263 ms
320,048 KB
testcase_01 AC 1,130 ms
320,032 KB
testcase_02 AC 1,267 ms
320,048 KB
testcase_03 AC 1,153 ms
320,048 KB
testcase_04 AC 1,272 ms
320,048 KB
testcase_05 AC 1,134 ms
320,032 KB
testcase_06 AC 1,280 ms
320,432 KB
testcase_07 AC 1,192 ms
320,416 KB
testcase_08 AC 1,285 ms
320,432 KB
testcase_09 AC 1,296 ms
320,416 KB
testcase_10 AC 1,473 ms
320,416 KB
testcase_11 AC 1,407 ms
320,416 KB
testcase_12 AC 1,797 ms
320,432 KB
testcase_13 AC 1,552 ms
320,432 KB
testcase_14 AC 1,261 ms
320,032 KB
testcase_15 AC 1,684 ms
320,416 KB
testcase_16 AC 1,510 ms
320,416 KB
testcase_17 AC 1,440 ms
320,416 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