結果

問題 No.2364 Knapsack Problem
ユーザー ShirotsumeShirotsume
提出日時 2023-06-30 22:23:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,819 ms / 3,000 ms
コード長 1,473 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 86,484 KB
実行使用メモリ 81,828 KB
最終ジャッジ日時 2023-09-21 16:30:45
合計ジャッジ時間 8,060 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
74,464 KB
testcase_01 AC 117 ms
74,028 KB
testcase_02 AC 120 ms
74,420 KB
testcase_03 AC 116 ms
74,608 KB
testcase_04 AC 118 ms
74,468 KB
testcase_05 AC 118 ms
74,604 KB
testcase_06 AC 119 ms
74,428 KB
testcase_07 AC 198 ms
81,440 KB
testcase_08 AC 117 ms
74,532 KB
testcase_09 AC 148 ms
81,312 KB
testcase_10 AC 159 ms
81,764 KB
testcase_11 AC 155 ms
81,128 KB
testcase_12 AC 176 ms
81,436 KB
testcase_13 AC 537 ms
81,600 KB
testcase_14 AC 411 ms
81,828 KB
testcase_15 AC 214 ms
81,320 KB
testcase_16 AC 185 ms
81,468 KB
testcase_17 AC 158 ms
81,264 KB
testcase_18 AC 2,819 ms
81,460 KB
testcase_19 AC 178 ms
81,644 KB
testcase_20 AC 153 ms
81,508 KB
testcase_21 AC 189 ms
81,144 KB
権限があれば一括ダウンロードができます

ソースコード

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
import itertools
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
for bit1 in range(1 << n):
    for bit2 in range(1 << m):
        if time.time() - t1 >= 2.7:
            print(ans)
            exit()

        WV = []
        p = 0
        for i in range(n):
            if 1 & (bit1 >> i):
                WV.append((a[i], b[i]))
                p += b[i]
        if ans >= p:
            break
        WIS = []
        for i in range(m):
            if 1 & (bit2 >> i):
                WIS.append((c[i], d[i]))
                p -= d[i]
        if ans >= p:
        	continue
        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)
print(ans)
0