結果

問題 No.2364 Knapsack Problem
ユーザー yabityabit
提出日時 2023-06-30 21:43:55
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,027 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 79,152 KB
最終ジャッジ日時 2023-09-21 15:38:30
合計ジャッジ時間 3,968 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,508 KB
testcase_01 AC 76 ms
71,364 KB
testcase_02 AC 77 ms
71,336 KB
testcase_03 RE -
testcase_04 AC 79 ms
71,600 KB
testcase_05 AC 77 ms
71,456 KB
testcase_06 WA -
testcase_07 RE -
testcase_08 AC 73 ms
71,724 KB
testcase_09 AC 116 ms
76,772 KB
testcase_10 AC 103 ms
77,332 KB
testcase_11 RE -
testcase_12 AC 111 ms
77,296 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 112 ms
77,216 KB
testcase_16 AC 112 ms
77,412 KB
testcase_17 WA -
testcase_18 AC 114 ms
77,492 KB
testcase_19 AC 116 ms
77,304 KB
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import product

N, M, W = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))
ans = 0
for pr1 in product((0, 1), repeat=N):
    for pr2 in product((0, 1), repeat=M):
        Wc = []
        wi, vi = 0, 0
        for i in range(N):
            if pr1[i]:
                Wc.append(A[i])
                vi += B[i]
        for i in range(N):
            if pr2[i]:
                Wc.append(-C[i])
                vi -= D[i]
        Wc.sort()
        l, r = 0, len(Wc) - 1
        while l <= r:
            # print(l, r, Wc)
            if 0 <= Wc[l] + wi <= W:
                wi += Wc[l]
                l += 1
                continue
            elif 0 <= Wc[r] + wi <= W:
                wi += Wc[r]
                r -= 1
                continue
            else:
                break
        if l > r:
            ans = max(ans, vi)
        # print(pr1, pr2, l == r, ans, Wc)
print(ans)
0