結果

問題 No.2026 Yet Another Knapsack Problem
ユーザー chineristACchineristAC
提出日時 2022-04-24 12:44:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,903 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 86,768 KB
実行使用メモリ 150,604 KB
最終ジャッジ日時 2023-09-09 19:45:40
合計ジャッジ時間 56,301 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 244 ms
92,384 KB
testcase_01 AC 241 ms
92,520 KB
testcase_02 AC 239 ms
92,664 KB
testcase_03 AC 310 ms
95,560 KB
testcase_04 AC 301 ms
96,212 KB
testcase_05 WA -
testcase_06 AC 329 ms
96,136 KB
testcase_07 AC 311 ms
95,512 KB
testcase_08 AC 266 ms
94,960 KB
testcase_09 AC 329 ms
96,088 KB
testcase_10 AC 297 ms
95,620 KB
testcase_11 AC 333 ms
96,624 KB
testcase_12 AC 242 ms
92,496 KB
testcase_13 AC 323 ms
95,952 KB
testcase_14 AC 314 ms
95,760 KB
testcase_15 AC 246 ms
92,464 KB
testcase_16 AC 310 ms
96,060 KB
testcase_17 AC 303 ms
95,864 KB
testcase_18 AC 250 ms
92,312 KB
testcase_19 AC 312 ms
95,496 KB
testcase_20 AC 248 ms
92,528 KB
testcase_21 AC 318 ms
95,736 KB
testcase_22 AC 298 ms
95,804 KB
testcase_23 AC 341 ms
96,680 KB
testcase_24 AC 255 ms
92,600 KB
testcase_25 AC 254 ms
92,656 KB
testcase_26 AC 349 ms
96,620 KB
testcase_27 AC 311 ms
96,092 KB
testcase_28 AC 518 ms
98,068 KB
testcase_29 AC 546 ms
98,784 KB
testcase_30 AC 558 ms
99,884 KB
testcase_31 AC 530 ms
98,668 KB
testcase_32 AC 472 ms
97,896 KB
testcase_33 AC 537 ms
99,084 KB
testcase_34 AC 504 ms
98,552 KB
testcase_35 AC 487 ms
98,220 KB
testcase_36 AC 513 ms
98,724 KB
testcase_37 AC 516 ms
98,860 KB
testcase_38 AC 5,354 ms
147,824 KB
testcase_39 AC 5,945 ms
150,604 KB
testcase_40 AC 5,809 ms
148,920 KB
testcase_41 AC 5,845 ms
148,948 KB
testcase_42 AC 5,819 ms
148,588 KB
testcase_43 WA -
testcase_44 AC 5,530 ms
149,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
    

0