結果

問題 No.2026 Yet Another Knapsack Problem
ユーザー suisensuisen
提出日時 2022-07-30 00:38:32
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 4,181 ms / 10,000 ms
コード長 608 bytes
コンパイル時間 1,162 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 128,376 KB
最終ジャッジ日時 2023-09-27 01:06:42
合計ジャッジ時間 33,318 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,296 KB
testcase_01 AC 77 ms
71,364 KB
testcase_02 AC 78 ms
71,648 KB
testcase_03 AC 92 ms
76,340 KB
testcase_04 AC 90 ms
76,540 KB
testcase_05 AC 81 ms
76,116 KB
testcase_06 AC 91 ms
76,340 KB
testcase_07 AC 90 ms
76,332 KB
testcase_08 AC 85 ms
76,188 KB
testcase_09 AC 98 ms
76,640 KB
testcase_10 AC 91 ms
76,532 KB
testcase_11 AC 96 ms
76,608 KB
testcase_12 AC 75 ms
71,248 KB
testcase_13 AC 98 ms
76,700 KB
testcase_14 AC 93 ms
76,364 KB
testcase_15 AC 76 ms
71,136 KB
testcase_16 AC 92 ms
76,636 KB
testcase_17 AC 88 ms
76,724 KB
testcase_18 AC 76 ms
71,480 KB
testcase_19 AC 90 ms
76,476 KB
testcase_20 AC 76 ms
71,364 KB
testcase_21 AC 90 ms
76,600 KB
testcase_22 AC 89 ms
76,680 KB
testcase_23 AC 92 ms
76,572 KB
testcase_24 AC 76 ms
71,560 KB
testcase_25 AC 84 ms
76,512 KB
testcase_26 AC 96 ms
76,600 KB
testcase_27 AC 89 ms
76,492 KB
testcase_28 AC 194 ms
79,048 KB
testcase_29 AC 194 ms
79,788 KB
testcase_30 AC 206 ms
79,444 KB
testcase_31 AC 196 ms
79,604 KB
testcase_32 AC 191 ms
78,704 KB
testcase_33 AC 229 ms
79,580 KB
testcase_34 AC 195 ms
79,304 KB
testcase_35 AC 176 ms
78,512 KB
testcase_36 AC 195 ms
78,956 KB
testcase_37 AC 188 ms
79,028 KB
testcase_38 AC 3,002 ms
127,200 KB
testcase_39 AC 4,167 ms
127,840 KB
testcase_40 AC 3,746 ms
127,944 KB
testcase_41 AC 4,003 ms
127,732 KB
testcase_42 AC 3,619 ms
127,924 KB
testcase_43 AC 3,781 ms
128,100 KB
testcase_44 AC 4,181 ms
128,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 1 << 60

N = int(input())
C = [0] * (N + 1)
V = [0] * (N + 1)

for w in range(1, N + 1):
    C[w], V[w] = map(int, input().split())

dp = [[-INF] * (N + 1) for _ in range(N + 1)]
dp[0] = [0] * (N + 1)

for w in reversed(range(1, N + 1)):
    pw = 1
    while C[w]:
        k = min(pw, C[w])
        C[w] -= k
        dw = k * w
        dv = k * V[w]

        for num in reversed(range(k, N // w + 1)):
            for wsum in reversed(range(dw, N + 1)):
                dp[num][wsum] = max(dp[num][wsum], dp[num - k][wsum - dw] + dv)
        pw <<= 1

for num in range(1, N + 1):
    print(dp[num][N])
0