結果
| 問題 |
No.3046 White Tiger vs Monster
|
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:18:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,842 bytes |
| コンパイル時間 | 305 ms |
| コンパイル使用メモリ | 82,288 KB |
| 実行使用メモリ | 131,764 KB |
| 最終ジャッジ日時 | 2025-06-12 16:19:30 |
| 合計ジャッジ時間 | 12,642 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 1 WA * 79 |
ソースコード
import bisect
MOD = 10**9 + 7
class FenwickTree:
def __init__(self, size):
self.size = size
self.tree = [0] * (size + 1) # 1-based indexing
def update(self, index, value):
while index <= self.size:
self.tree[index] = (self.tree[index] + value) % MOD
index += index & -index
def query(self, index):
res = 0
while index > 0:
res = (res + self.tree[index]) % MOD
index -= index & -index
return res
def main():
import sys
input = sys.stdin.read().split()
ptr = 0
K = int(input[ptr])
ptr += 1
N = int(input[ptr])
ptr += 1
x = list(map(int, input[ptr:ptr+N]))
ptr += N
x.sort() # Ensure x is sorted
max_k = K
fenwick = FenwickTree(max_k)
dp = [0] * (max_k + 1)
dp[0] = 1
fenwick.update(0 + 1, dp[0]) # Fenwick is 1-based
for k in range(1, max_k + 1):
# Find the largest x_i <= k
m = bisect.bisect_right(x, k) - 1
if m < 0:
dp_k = 0
else:
# Compute the sum of dp[k - x_i] for i=0 to m
# Since x is sorted, k - x_i may be in a non-contiguous range
# Thus, we need to query each x_i individually, which is O(m) time and not feasible
# This approach is incorrect as it leads to O(N) per k
# Hence, the code below is incorrect for the problem constraints
sum_dp = 0
for i in range(m + 1):
xi = x[i]
if xi > k:
break
j = k - xi
if j < 0:
continue
sum_dp = (sum_dp + dp[j]) % MOD
dp_k = sum_dp
dp[k] = dp_k
fenwick.update(k + 1, dp_k)
print(dp[K] % MOD)
if __name__ == "__main__":
main()
gew1fw