結果

問題 No.2130 分配方法の数え上げ mod 998244353
ユーザー Nikkuniku029Nikkuniku029
提出日時 2022-11-25 21:57:59
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 835 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,272 KB
実行使用メモリ 72,196 KB
最終ジャッジ日時 2024-04-10 03:10:07
合計ジャッジ時間 7,085 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
63,776 KB
testcase_01 AC 140 ms
63,052 KB
testcase_02 AC 138 ms
63,332 KB
testcase_03 AC 138 ms
61,860 KB
testcase_04 AC 139 ms
62,460 KB
testcase_05 AC 139 ms
62,980 KB
testcase_06 AC 138 ms
63,736 KB
testcase_07 AC 139 ms
63,052 KB
testcase_08 AC 137 ms
61,652 KB
testcase_09 AC 139 ms
62,024 KB
testcase_10 AC 140 ms
62,120 KB
testcase_11 AC 140 ms
62,484 KB
testcase_12 AC 138 ms
62,196 KB
testcase_13 AC 139 ms
63,124 KB
testcase_14 AC 138 ms
63,208 KB
testcase_15 AC 139 ms
62,480 KB
testcase_16 AC 140 ms
62,200 KB
testcase_17 AC 143 ms
66,032 KB
testcase_18 AC 143 ms
65,952 KB
testcase_19 AC 144 ms
67,108 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
M = int(input())
MOD = 998244353


def modinv(x):
    return pow(x, MOD-2, MOD)

# 二項係数の左側の数字の最大値を max_len とする。nとかだと他の変数と被りそうなので。
# factori_table = [1, 1, 2, 6, 24, 120, ...] 要は factori_table[n] = n!
# 計算時間はO(max_len * log(MOD))


max_len = 10**5 + 2

factori_table = [1] * (max_len + 1)
factori_inv_table = [1] * (max_len + 1)
for i in range(1, max_len + 1):
    factori_table[i] = factori_table[i-1] * (i) % MOD
    factori_inv_table[i] = modinv(factori_table[i])


def binomial_coefficients(n, k):
    # n! / (k! * (n-k)! )
    return factori_table[n] * factori_inv_table[k] * factori_inv_table[n-k]


ans = pow(2, N, MOD)

for m in range(M):
    if N >= m:
        ans -= binomial_coefficients(N, m)
    ans %= MOD
print(ans)
0