結果
問題 | No.2026 Yet Another Knapsack Problem |
ユーザー | chineristAC |
提出日時 | 2022-04-24 12:44:32 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,903 bytes |
コンパイル時間 | 307 ms |
コンパイル使用メモリ | 82,244 KB |
実行使用メモリ | 143,948 KB |
最終ジャッジ日時 | 2024-06-27 12:20:50 |
合計ジャッジ時間 | 48,471 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 137 ms
88,768 KB |
testcase_01 | AC | 139 ms
88,700 KB |
testcase_02 | AC | 139 ms
89,000 KB |
testcase_03 | AC | 212 ms
90,536 KB |
testcase_04 | AC | 198 ms
90,484 KB |
testcase_05 | WA | - |
testcase_06 | AC | 219 ms
90,696 KB |
testcase_07 | AC | 200 ms
90,460 KB |
testcase_08 | AC | 162 ms
89,636 KB |
testcase_09 | AC | 229 ms
90,748 KB |
testcase_10 | AC | 191 ms
90,496 KB |
testcase_11 | AC | 224 ms
90,976 KB |
testcase_12 | AC | 139 ms
88,776 KB |
testcase_13 | AC | 224 ms
90,808 KB |
testcase_14 | AC | 201 ms
90,476 KB |
testcase_15 | AC | 137 ms
88,644 KB |
testcase_16 | AC | 206 ms
90,528 KB |
testcase_17 | AC | 196 ms
90,536 KB |
testcase_18 | AC | 142 ms
88,960 KB |
testcase_19 | AC | 201 ms
90,536 KB |
testcase_20 | AC | 136 ms
88,892 KB |
testcase_21 | AC | 200 ms
90,460 KB |
testcase_22 | AC | 179 ms
90,368 KB |
testcase_23 | AC | 223 ms
90,820 KB |
testcase_24 | AC | 145 ms
88,980 KB |
testcase_25 | AC | 140 ms
88,920 KB |
testcase_26 | AC | 225 ms
90,880 KB |
testcase_27 | AC | 186 ms
90,532 KB |
testcase_28 | AC | 401 ms
92,616 KB |
testcase_29 | AC | 410 ms
93,144 KB |
testcase_30 | AC | 422 ms
93,196 KB |
testcase_31 | AC | 403 ms
93,072 KB |
testcase_32 | AC | 341 ms
92,268 KB |
testcase_33 | AC | 419 ms
93,072 KB |
testcase_34 | AC | 378 ms
92,840 KB |
testcase_35 | AC | 357 ms
92,032 KB |
testcase_36 | AC | 390 ms
92,304 KB |
testcase_37 | AC | 386 ms
92,936 KB |
testcase_38 | AC | 4,984 ms
141,952 KB |
testcase_39 | AC | 5,467 ms
143,948 KB |
testcase_40 | AC | 5,533 ms
142,784 KB |
testcase_41 | AC | 5,441 ms
143,104 KB |
testcase_42 | AC | 5,365 ms
142,664 KB |
testcase_43 | WA | - |
testcase_44 | AC | 5,276 ms
143,500 KB |
ソースコード
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()) 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//(i+1) 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)