結果
問題 | No.2364 Knapsack Problem |
ユーザー | Shirotsume |
提出日時 | 2023-06-30 22:11:54 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,290 bytes |
コンパイル時間 | 135 ms |
コンパイル使用メモリ | 82,180 KB |
実行使用メモリ | 78,096 KB |
最終ジャッジ日時 | 2024-07-07 10:00:28 |
合計ジャッジ時間 | 3,439 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
55,424 KB |
testcase_01 | AC | 38 ms
55,424 KB |
testcase_02 | AC | 44 ms
64,256 KB |
testcase_03 | AC | 37 ms
55,936 KB |
testcase_04 | AC | 55 ms
70,144 KB |
testcase_05 | AC | 71 ms
76,800 KB |
testcase_06 | AC | 58 ms
71,296 KB |
testcase_07 | WA | - |
testcase_08 | AC | 38 ms
55,808 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 74 ms
77,436 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
ソースコード
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 <= 10: 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)