結果
問題 | No.2364 Knapsack Problem |
ユーザー | McGregorsh |
提出日時 | 2023-06-30 22:10:50 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,922 bytes |
コンパイル時間 | 212 ms |
コンパイル使用メモリ | 82,128 KB |
実行使用メモリ | 90,200 KB |
最終ジャッジ日時 | 2024-07-07 09:59:12 |
合計ジャッジ時間 | 5,018 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 118 ms
88,476 KB |
testcase_01 | AC | 112 ms
88,604 KB |
testcase_02 | AC | 119 ms
88,684 KB |
testcase_03 | AC | 114 ms
88,424 KB |
testcase_04 | AC | 123 ms
89,320 KB |
testcase_05 | AC | 129 ms
89,388 KB |
testcase_06 | AC | 123 ms
89,508 KB |
testcase_07 | AC | 173 ms
89,868 KB |
testcase_08 | AC | 113 ms
88,344 KB |
testcase_09 | WA | - |
testcase_10 | AC | 161 ms
89,816 KB |
testcase_11 | AC | 128 ms
89,112 KB |
testcase_12 | AC | 215 ms
89,960 KB |
testcase_13 | AC | 222 ms
90,044 KB |
testcase_14 | WA | - |
testcase_15 | AC | 218 ms
89,868 KB |
testcase_16 | AC | 231 ms
89,772 KB |
testcase_17 | AC | 231 ms
89,956 KB |
testcase_18 | AC | 220 ms
90,032 KB |
testcase_19 | AC | 215 ms
90,052 KB |
testcase_20 | AC | 219 ms
89,848 KB |
testcase_21 | AC | 231 ms
90,036 KB |
ソースコード
import sys from sys import stdin from fractions import Fraction import math from math import ceil, floor, sqrt, pi, factorial, gcd from copy import deepcopy from collections import Counter, deque, defaultdict from heapq import heapify, heappop, heappush from itertools import accumulate, product, combinations, combinations_with_replacement, permutations from bisect import bisect, bisect_left, bisect_right from functools import reduce, lru_cache from decimal import Decimal, getcontext, ROUND_HALF_UP def i_input(): return int(stdin.readline()) def i_map(): return map(int, stdin.readline().split()) def i_list(): return list(i_map()) def s_input(): return stdin.readline()[:-1] def s_map(): return s_input().split() def s_list(): return list(s_map()) def lcm(a, b): return a * b // gcd(a, b) def get_distance(x1, y1, x2, y2): d = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) return d def rotate(table): n_fild = [] for x in zip(*table[::-1]): n_fild.append(x) return n_fild sys.setrecursionlimit(10 ** 7) INF = float('inf') MOD = 10 ** 9 + 7 MOD2 = 998244353 alpa = 'abcdefghijklmnopqrstuvwxyz' ALPA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' def main(): N, M, W = i_map() A = i_list() B = i_list() C = i_list() D = i_list() for i in range(M): C[i] *= -1 D[i] *= -1 w = A + C v = B + D dp = [-INF] * (2 ** (N+M)) dp[0] = 0 for i in range(2**(N+M)): for j in range(N+M): a, b = w[j], v[j] p = 2 ** j if i | p != i: nxt = i | p flag = format(nxt, 'b').zfill(N+M)[::-1] cou = 0 for k in range(N+M): if flag[k] == '1': cou += w[k] if cou <= W: dp[nxt] = max(dp[nxt], dp[i] + b) print(max(dp)) if __name__ == '__main__': main()