結果

問題 No.2130 分配方法の数え上げ mod 998244353
ユーザー Nikkuniku029Nikkuniku029
提出日時 2022-11-25 21:54:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 828 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 112,572 KB
最終ジャッジ日時 2024-04-10 03:05:56
合計ジャッジ時間 5,186 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
17,696 KB
testcase_01 AC 28 ms
10,752 KB
testcase_02 AC 26 ms
10,752 KB
testcase_03 AC 27 ms
10,752 KB
testcase_04 AC 27 ms
10,624 KB
testcase_05 AC 26 ms
10,880 KB
testcase_06 AC 26 ms
10,624 KB
testcase_07 AC 26 ms
10,752 KB
testcase_08 AC 27 ms
10,752 KB
testcase_09 AC 28 ms
10,752 KB
testcase_10 AC 28 ms
10,624 KB
testcase_11 AC 28 ms
10,624 KB
testcase_12 AC 28 ms
10,880 KB
testcase_13 AC 29 ms
10,752 KB
testcase_14 AC 31 ms
10,624 KB
testcase_15 AC 31 ms
10,752 KB
testcase_16 AC 36 ms
10,752 KB
testcase_17 AC 56 ms
11,264 KB
testcase_18 AC 83 ms
11,392 KB
testcase_19 AC 475 ms
17,152 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = N

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