結果

問題 No.2026 Yet Another Knapsack Problem
ユーザー chineristACchineristAC
提出日時 2022-04-24 13:10:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,912 bytes
コンパイル時間 1,496 ms
コンパイル使用メモリ 86,764 KB
実行使用メモリ 101,408 KB
最終ジャッジ日時 2023-09-09 19:44:39
合計ジャッジ時間 97,352 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 240 ms
92,648 KB
testcase_01 AC 242 ms
93,664 KB
testcase_02 AC 241 ms
92,584 KB
testcase_03 AC 382 ms
96,388 KB
testcase_04 AC 356 ms
96,000 KB
testcase_05 WA -
testcase_06 AC 415 ms
96,220 KB
testcase_07 AC 386 ms
96,820 KB
testcase_08 AC 296 ms
95,756 KB
testcase_09 AC 430 ms
96,816 KB
testcase_10 AC 373 ms
96,468 KB
testcase_11 AC 426 ms
96,008 KB
testcase_12 AC 242 ms
93,432 KB
testcase_13 AC 427 ms
96,460 KB
testcase_14 AC 383 ms
95,916 KB
testcase_15 AC 247 ms
92,544 KB
testcase_16 AC 381 ms
95,880 KB
testcase_17 AC 352 ms
96,368 KB
testcase_18 AC 260 ms
92,648 KB
testcase_19 AC 348 ms
95,732 KB
testcase_20 AC 241 ms
92,680 KB
testcase_21 AC 331 ms
95,788 KB
testcase_22 AC 326 ms
95,320 KB
testcase_23 AC 397 ms
96,292 KB
testcase_24 AC 249 ms
92,528 KB
testcase_25 AC 263 ms
95,008 KB
testcase_26 AC 404 ms
96,860 KB
testcase_27 AC 320 ms
96,308 KB
testcase_28 AC 8,279 ms
100,068 KB
testcase_29 AC 9,153 ms
100,864 KB
testcase_30 AC 8,828 ms
101,408 KB
testcase_31 AC 8,614 ms
100,072 KB
testcase_32 AC 6,053 ms
99,944 KB
testcase_33 TLE -
testcase_34 AC 8,659 ms
100,180 KB
testcase_35 AC 5,671 ms
99,364 KB
testcase_36 AC 7,688 ms
99,576 KB
testcase_37 AC 8,627 ms
99,856 KB
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
権限があれば一括ダウンロードができます

ソースコード

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())
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)
    

0