結果
問題 | No.2364 Knapsack Problem |
ユーザー | Shirotsume |
提出日時 | 2023-06-30 22:12:34 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,290 bytes |
コンパイル時間 | 293 ms |
コンパイル使用メモリ | 87,128 KB |
実行使用メモリ | 82,668 KB |
最終ジャッジ日時 | 2023-09-21 16:15:54 |
合計ジャッジ時間 | 7,308 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 115 ms
74,256 KB |
testcase_01 | AC | 116 ms
74,428 KB |
testcase_02 | AC | 126 ms
79,280 KB |
testcase_03 | AC | 117 ms
74,216 KB |
testcase_04 | AC | 140 ms
79,248 KB |
testcase_05 | AC | 159 ms
81,048 KB |
testcase_06 | AC | 145 ms
81,244 KB |
testcase_07 | AC | 196 ms
81,816 KB |
testcase_08 | AC | 114 ms
74,588 KB |
testcase_09 | AC | 232 ms
81,652 KB |
testcase_10 | AC | 675 ms
81,648 KB |
testcase_11 | AC | 158 ms
81,276 KB |
testcase_12 | AC | 343 ms
81,796 KB |
testcase_13 | AC | 342 ms
82,212 KB |
testcase_14 | WA | - |
testcase_15 | AC | 343 ms
81,540 KB |
testcase_16 | AC | 341 ms
81,892 KB |
testcase_17 | AC | 364 ms
81,712 KB |
testcase_18 | AC | 327 ms
81,716 KB |
testcase_19 | AC | 348 ms
81,636 KB |
testcase_20 | AC | 403 ms
82,572 KB |
testcase_21 | AC | 413 ms
82,668 KB |
ソースコード
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 if n + m <= 12: 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])) for WV in itertools.permutations(WV): 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) else: 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)