結果
問題 |
No.3046 White Tiger vs Monster
|
ユーザー |
![]() |
提出日時 | 2025-04-16 15:59:06 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 932 bytes |
コンパイル時間 | 475 ms |
コンパイル使用メモリ | 81,876 KB |
実行使用メモリ | 67,416 KB |
最終ジャッジ日時 | 2025-04-16 16:01:12 |
合計ジャッジ時間 | 7,840 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 3 |
other | RE * 80 |
ソースコード
MOD = 10**9 + 7 K = int(input()) N = int(input()) x = list(map(int, input().split())) # Filter x to include only steps <= K and sort them x = [xi for xi in x if xi <= K] x.sort() dp = [0] * (K + 1) sum_dp = [0] * (K + 1) dp[0] = 1 sum_dp[0] = 1 for k in range(1, K + 1): total = 0 # Find the rightmost index where x_i <= k using binary search left, right = 0, len(x) while left < right: mid = (left + right) // 2 if x[mid] <= k: left = mid + 1 else: right = mid # Iterate through all valid x_i (up to left-1) for xi in x[:left]: prev = k - xi if prev >= 0: total += sum_dp[prev] if prev - 1 >= 0: total -= sum_dp[prev - 1] # Ensure the total stays within the modulo bounds total %= MOD dp[k] = total % MOD sum_dp[k] = (sum_dp[k - 1] + dp[k]) % MOD print(dp[K] % MOD)