結果
問題 | No.2026 Yet Another Knapsack Problem |
ユーザー | chineristAC |
提出日時 | 2022-04-24 13:10:47 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,912 bytes |
コンパイル時間 | 661 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 95,152 KB |
最終ジャッジ日時 | 2024-06-27 12:19:56 |
合計ジャッジ時間 | 83,670 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 141 ms
88,988 KB |
testcase_01 | AC | 146 ms
89,964 KB |
testcase_02 | AC | 140 ms
88,960 KB |
testcase_03 | AC | 269 ms
90,620 KB |
testcase_04 | AC | 245 ms
90,388 KB |
testcase_05 | WA | - |
testcase_06 | AC | 318 ms
90,936 KB |
testcase_07 | AC | 272 ms
90,880 KB |
testcase_08 | AC | 199 ms
90,240 KB |
testcase_09 | AC | 327 ms
90,752 KB |
testcase_10 | AC | 278 ms
90,740 KB |
testcase_11 | AC | 322 ms
91,008 KB |
testcase_12 | AC | 145 ms
89,600 KB |
testcase_13 | AC | 314 ms
90,752 KB |
testcase_14 | AC | 277 ms
90,368 KB |
testcase_15 | AC | 142 ms
89,024 KB |
testcase_16 | AC | 272 ms
90,496 KB |
testcase_17 | AC | 236 ms
90,328 KB |
testcase_18 | AC | 144 ms
88,960 KB |
testcase_19 | AC | 248 ms
90,496 KB |
testcase_20 | AC | 140 ms
88,960 KB |
testcase_21 | AC | 223 ms
90,368 KB |
testcase_22 | AC | 224 ms
90,368 KB |
testcase_23 | AC | 287 ms
90,752 KB |
testcase_24 | AC | 142 ms
88,960 KB |
testcase_25 | AC | 161 ms
89,856 KB |
testcase_26 | AC | 297 ms
91,136 KB |
testcase_27 | AC | 216 ms
90,952 KB |
testcase_28 | AC | 7,085 ms
94,080 KB |
testcase_29 | AC | 7,912 ms
94,592 KB |
testcase_30 | AC | 7,967 ms
95,152 KB |
testcase_31 | AC | 8,278 ms
94,144 KB |
testcase_32 | AC | 5,422 ms
93,272 KB |
testcase_33 | AC | 9,768 ms
94,228 KB |
testcase_34 | AC | 7,853 ms
94,164 KB |
testcase_35 | AC | 5,092 ms
93,672 KB |
testcase_36 | AC | 6,754 ms
94,720 KB |
testcase_37 | AC | 7,889 ms
94,208 KB |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
ソースコード
import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import gcd from fractions import Fraction input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) local_test = False def random_test(N): item = [(N,random.randint(-10**9,10**9))] for i in range(1,N): c = random.randint(1,N) v = random.randint(-10**9,10**9) item.append((c,v)) return item INF = 10**17 N = int(input()) assert N <= 500 if local_test: item = random_test(N) else: item = [tuple(mi()) for i in range(N)] dp = [[-INF]*(N+1) for i in range(N+1)] dp[0][0] = 0 for i in range(N)[::-1]: c,v = item[i] k_max = N for w_start in range(i+1): for k_start in range(k_max+1): deq = deque() for k in range(k_start,k_max+1): w = w_start + (k-k_start) * (i+1) if N < w: break if deq and deq[0][1] < k-c: deq.popleft() tmp = dp[w][k] - k * v while deq and deq[0][0] <= tmp: deq.pop() deq.append((tmp,k)) dp[w][k] = v*k + deq[0][0] for w_start in range(i+1,N+1): for k_start in range(1): deq = deque() for k in range(k_start,k_max+1): w = w_start + (k-k_start) * (i+1) if N < w: break if deq and deq[0][1] < k-c: deq.popleft() tmp = dp[w][k] - k * v while deq and deq[0][0] <= tmp: deq.pop() deq.append((tmp,k)) dp[w][k] = v*k + deq[0][0] for k in range(1,N+1): res = max(dp[w][k] for w in range(N+1)) print(res)