結果

問題 No.2364 Knapsack Problem
ユーザー ShirotsumeShirotsume
提出日時 2023-06-30 22:05:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,199 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 87,016 KB
実行使用メモリ 83,104 KB
最終ジャッジ日時 2023-09-21 16:06:30
合計ジャッジ時間 6,785 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
74,292 KB
testcase_01 AC 117 ms
74,724 KB
testcase_02 AC 129 ms
79,080 KB
testcase_03 AC 117 ms
74,360 KB
testcase_04 AC 128 ms
79,264 KB
testcase_05 AC 155 ms
81,208 KB
testcase_06 AC 126 ms
79,448 KB
testcase_07 WA -
testcase_08 AC 118 ms
74,472 KB
testcase_09 AC 174 ms
81,464 KB
testcase_10 AC 197 ms
81,716 KB
testcase_11 AC 131 ms
79,400 KB
testcase_12 AC 358 ms
82,228 KB
testcase_13 WA -
testcase_14 AC 335 ms
81,656 KB
testcase_15 AC 368 ms
81,804 KB
testcase_16 AC 388 ms
82,384 KB
testcase_17 WA -
testcase_18 AC 333 ms
82,240 KB
testcase_19 AC 370 ms
82,204 KB
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353
import time
t1 = time.time()
n, m, w = mi()

a = li()
b = li()
c = [-v for v in li()]
d = [-v for v in li()]
ans = 0
import itertools
for bit1 in range(1 << n):
    for bit2 in range(1 << m):
        WV = []
        for i in range(n):
            if 1 & (bit1 >> i):
                WV.append((a[i], b[i]))
        WIS = []
        for i in range(m):
            if 1 & (bit2 >> i):
                WIS.append((c[i], d[i]))
        WV.sort(key = lambda x: x[0], reverse=True)
        for WIS in itertools.permutations(WIS):
            j = 0
            noww = 0
            nowv = 0
            for x, y in WV:
                noww += x
                nowv += y
                if noww > w:
                    nowv = -inf
                    break
                if j < len(WIS) and -WIS[j][0] <= noww:
                    noww += WIS[j][0]
                    nowv += WIS[j][1]
                    j += 1
            ans = max(ans, nowv)
print(ans)
0