結果

問題 No.2364 Knapsack Problem
ユーザー sepa38sepa38
提出日時 2023-06-30 21:39:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 119 ms / 3,000 ms
コード長 760 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 77,664 KB
最終ジャッジ日時 2023-09-21 15:32:58
合計ジャッジ時間 3,642 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,344 KB
testcase_01 AC 71 ms
71,460 KB
testcase_02 AC 71 ms
71,316 KB
testcase_03 AC 75 ms
71,424 KB
testcase_04 AC 86 ms
76,692 KB
testcase_05 AC 93 ms
76,672 KB
testcase_06 AC 87 ms
76,692 KB
testcase_07 AC 110 ms
76,544 KB
testcase_08 AC 76 ms
71,140 KB
testcase_09 AC 100 ms
76,828 KB
testcase_10 AC 102 ms
76,732 KB
testcase_11 AC 91 ms
76,688 KB
testcase_12 AC 119 ms
77,664 KB
testcase_13 AC 113 ms
77,592 KB
testcase_14 AC 114 ms
77,540 KB
testcase_15 AC 115 ms
77,612 KB
testcase_16 AC 107 ms
76,720 KB
testcase_17 AC 100 ms
76,640 KB
testcase_18 AC 103 ms
76,688 KB
testcase_19 AC 116 ms
77,568 KB
testcase_20 AC 110 ms
77,612 KB
testcase_21 AC 104 ms
76,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m, w = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(lambda x: -int(x), input().split()))
d = list(map(lambda x: -int(x), input().split()))
ac = a + c
bd = b + d
k = n + m
weight = [0] * (1 << k)
value = [0] * (1 << k)
for i in range(1<<k):
  tmp = i
  for j in range(k):
    weight[i] += ac[j] * (tmp % 2)
    value[i] += bd[j] * (tmp % 2)
    tmp //= 2
flg = [0] * (1 << k)
# print(weight)
ans = 0
flg[0] = 1
for i in range(1<<k):
  if not 0 <= weight[i] <= w:
    continue
  for j in range(k):
    for l in range(k):
      if not 0 <= weight[i|(1<<l)] <= w:
        continue
      if i & (1 << l):
        continue
      flg[i|(1<<l)] |= flg[i]
  ans = max(ans, value[i]*flg[i])
print(ans)
0