結果
問題 |
No.1989 Pairing Multiset
|
ユーザー |
![]() |
提出日時 | 2025-03-31 17:51:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 66 ms / 2,000 ms |
コード長 | 705 bytes |
コンパイル時間 | 285 ms |
コンパイル使用メモリ | 82,592 KB |
実行使用メモリ | 60,508 KB |
最終ジャッジ日時 | 2025-03-31 17:52:02 |
合計ジャッジ時間 | 2,161 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
mod = 998244353 n, m = map(int, input().split()) A = m + 2 * n B = 2 * n + 1 if B > A: print(0) else: a_mod = A % mod # Compute numerator: product of (a_mod - k) mod mod for k from 0 to B-1 numerator = 1 for k in range(B): term = (a_mod - k) % mod numerator = (numerator * term) % mod # Compute B! mod mod factorial = 1 for i in range(1, B + 1): factorial = (factorial * i) % mod # Compute inverse of B! using Fermat's little theorem inv_factorial = pow(factorial, mod - 2, mod) # Calculate combination and final answer combination = (numerator * inv_factorial) % mod ans = (n * combination) % mod print(ans)