結果

問題 No.2130 分配方法の数え上げ mod 998244353
ユーザー Nikkuniku029Nikkuniku029
提出日時 2022-11-25 21:54:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 834 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 26,496 KB
最終ジャッジ日時 2024-04-10 03:07:13
合計ジャッジ時間 45,172 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,129 ms
26,368 KB
testcase_01 AC 1,127 ms
26,368 KB
testcase_02 AC 1,124 ms
26,368 KB
testcase_03 AC 1,109 ms
26,368 KB
testcase_04 AC 1,122 ms
26,240 KB
testcase_05 AC 1,114 ms
26,240 KB
testcase_06 AC 1,135 ms
26,368 KB
testcase_07 AC 1,121 ms
26,368 KB
testcase_08 AC 1,121 ms
26,368 KB
testcase_09 AC 1,115 ms
26,368 KB
testcase_10 AC 1,127 ms
26,240 KB
testcase_11 AC 1,110 ms
26,240 KB
testcase_12 AC 1,123 ms
26,368 KB
testcase_13 AC 1,120 ms
26,368 KB
testcase_14 AC 1,113 ms
26,240 KB
testcase_15 AC 1,125 ms
26,368 KB
testcase_16 AC 1,132 ms
26,368 KB
testcase_17 AC 1,137 ms
26,368 KB
testcase_18 AC 1,125 ms
26,496 KB
testcase_19 AC 1,123 ms
26,368 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 = 2*10**5

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