結果
| 問題 |
No.2381 Gift Exchange Party
|
| コンテスト | |
| ユーザー |
rlangevin
|
| 提出日時 | 2023-07-14 21:59:25 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 650 bytes |
| コンパイル時間 | 339 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 83,840 KB |
| 最終ジャッジ日時 | 2024-09-16 06:58:34 |
| 合計ジャッジ時間 | 3,255 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 RE * 7 |
ソースコード
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 )
rlangevin