結果
問題 |
No.3046 White Tiger vs Monster
|
ユーザー |
![]() |
提出日時 | 2025-06-12 21:25:25 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,776 bytes |
コンパイル時間 | 444 ms |
コンパイル使用メモリ | 82,156 KB |
実行使用メモリ | 67,344 KB |
最終ジャッジ日時 | 2025-06-12 21:26:08 |
合計ジャッジ時間 | 9,296 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 3 |
other | RE * 80 |
ソースコード
import bisect MOD = 10**9 + 7 def main(): import sys K = int(sys.stdin.readline()) N = int(sys.stdin.readline()) x = list(map(int, sys.stdin.readline().split())) dp = [0] * (K + 1) dp[0] = 1 pre = [0] * (K + 1) pre[0] = dp[0] for i in range(1, K + 1): # Find the maximum x_j <=i m = bisect.bisect_right(x, i) - 1 if m < 0: dp_i = 0 else: # Sum dp[i -x_0] + ... + dp[i -x_m] # i -x_j can be as low as i -x[-1] # So, the sum is pre[i - x_0 -1] - pre[i -x_m -1] # Wait, no, that's not correct because x is sorted # Wait, i -x_j can be any value, but the sum is dp[i-x_0] + dp[i-x_1] + ... dp[i-x_m] # Which is the sum of dp[k] where k = i -x_0, i -x_1, ..., i -x_m # But since x is sorted, x_0 < x_1 < ... <x_m, so i -x_0 > i -x_1 > ... > i -x_m # So the k's are in decreasing order. # So, the sum is the sum of dp[k] for k = i -x_0 down to i -x_m, but only if k >=0 # To compute this sum, we can compute pre[i -x_0] (if x_0 <=i) and subtract pre[i -x_m -1] if i -x_m >=0 # Wait, no. Because the sum is not a contiguous range. # So, the only way is to iterate through each x_j and add dp[i -x_j] # But this is O(N) per i, which is too slow. # So, we need a better approach. # Alternative approach: use a binary indexed tree to store dp and query the sum # However, given the time constraints, perhaps this is not feasible. # Given the time, perhaps the only way is to proceed with the O(N) approach for each i, but optimize with precomputed x. # But in Python, for K=1e5 and N=1e5, this is 1e10 operations, which is too slow. # So, perhaps the only way is to find a mathematical formula or find that the number of x_j's is small. # However, given the problem constraints, perhaps the intended solution is to use the O(K*N) approach with optimizations. # So, for this problem, I'll proceed with the O(K*N) approach, but it's unlikely to pass for large K and N. # But given the problem statement, perhaps the intended solution is to use the O(K) approach with a Fenwick Tree. # However, given time constraints, I'll proceed with an optimized approach. s = 0 for j in range(m + 1): k = i - x[j] if k >= 0: s += dp[k] if s >= MOD: s -= MOD dp_i = s % MOD dp[i] = dp_i pre[i] = (pre[i - 1] + dp[i]) % MOD print(dp[K] % MOD) if __name__ == "__main__": main()