結果
問題 | No.2364 Knapsack Problem |
ユーザー | flygon |
提出日時 | 2023-06-30 21:33:52 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,015 bytes |
コンパイル時間 | 1,755 ms |
コンパイル使用メモリ | 86,680 KB |
実行使用メモリ | 78,872 KB |
最終ジャッジ日時 | 2023-09-21 15:22:57 |
合計ジャッジ時間 | 4,729 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 89 ms
71,224 KB |
testcase_01 | AC | 88 ms
71,180 KB |
testcase_02 | AC | 91 ms
71,388 KB |
testcase_03 | AC | 91 ms
71,444 KB |
testcase_04 | AC | 117 ms
77,352 KB |
testcase_05 | AC | 105 ms
77,080 KB |
testcase_06 | WA | - |
testcase_07 | AC | 132 ms
78,200 KB |
testcase_08 | AC | 90 ms
71,460 KB |
testcase_09 | AC | 121 ms
77,476 KB |
testcase_10 | AC | 138 ms
78,244 KB |
testcase_11 | AC | 109 ms
77,372 KB |
testcase_12 | WA | - |
testcase_13 | AC | 149 ms
78,176 KB |
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 sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd n,m,W = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) d = list(map(int,input().split())) ans = 0 for bit in range(1<<(n+m)): v= 0 posw = [] negw = [] for i in range(n+m): if not(bit>>i) & 1: continue if i < n: posw.append(a[i]) v += b[i] else: negw.append(c[i-n]) v -= d[i-n] posw.sort() posw = posw[::-1] negw.sort() negw = negw[::-1] now = 0 ok = 1 while posw: now += posw.pop() ok &= (0<=now<= W) while negw and negw[-1] <= now: now -= negw.pop() while negw: now -= negw.pop() ok &= (0<=now<= W) ans = max(ans, ok*v) print(ans)