結果
問題 |
No.1186 長方形の敷き詰め
|
ユーザー |
![]() |
提出日時 | 2025-03-20 18:53:46 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 895 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 82,848 KB |
実行使用メモリ | 76,500 KB |
最終ジャッジ日時 | 2025-03-20 18:55:14 |
合計ジャッジ時間 | 2,642 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 WA * 3 |
ソースコード
MOD = 998244353 def main(): import sys input = sys.stdin.read().split() N = int(input[0]) M = int(input[1]) max_fact = M # since n can be up to M when k=0 # Precompute factorials and inverse factorials up to max_fact fact = [1] * (max_fact + 1) for i in range(1, max_fact + 1): fact[i] = fact[i-1] * i % MOD inv_fact = [1] * (max_fact + 1) inv_fact[max_fact] = pow(fact[max_fact], MOD-2, MOD) for i in range(max_fact - 1, -1, -1): inv_fact[i] = inv_fact[i+1] * (i+1) % MOD K = M // N ans = 0 for k in range(0, K + 1): n = M - k * (N - 1) # compute C(n, k) if k > n: comb = 0 else: comb = fact[n] * inv_fact[k] % MOD comb = comb * inv_fact[n - k] % MOD ans = (ans + comb) % MOD print(ans) if __name__ == "__main__": main()