結果

問題 No.2381 Gift Exchange Party
ユーザー rlangevinrlangevin
提出日時 2023-07-14 21:59:25
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 650 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 87,020 KB
実行使用メモリ 86,424 KB
最終ジャッジ日時 2023-10-14 12:08:42
合計ジャッジ時間 4,492 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
83,892 KB
testcase_01 AC 83 ms
84,140 KB
testcase_02 AC 90 ms
83,764 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 84 ms
83,812 KB
testcase_07 RE -
testcase_08 AC 84 ms
83,808 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 85 ms
83,816 KB
testcase_12 AC 84 ms
83,748 KB
testcase_13 AC 85 ms
83,912 KB
testcase_14 AC 92 ms
84,376 KB
testcase_15 AC 85 ms
83,844 KB
testcase_16 AC 86 ms
83,760 KB
testcase_17 AC 85 ms
83,652 KB
testcase_18 AC 84 ms
83,728 KB
testcase_19 AC 84 ms
83,960 KB
testcase_20 AC 197 ms
84,632 KB
testcase_21 RE -
testcase_22 AC 196 ms
84,808 KB
testcase_23 AC 198 ms
84,764 KB
testcase_24 AC 84 ms
84,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, P = map(int, input().split())
mod = 998244353
n = 505050
fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod
    
ans = 0
nokori = N
pm = 1
now = 1
cnt = 1
while now > 0:
    ans += now
    now *= comb(nokori, P) * fact[P - 1] * pow(cnt, mod - 2, mod)
    now %= mod
    ans %= mod
    nokori -= P
    cnt += 1
    
print( (fact[N] - ans) % mod )
0