結果

問題 No.50 おもちゃ箱
ユーザー Mao-betaMao-beta
提出日時 2024-03-02 02:21:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 159 ms / 5,000 ms
コード長 1,524 bytes
コンパイル時間 1,643 ms
コンパイル使用メモリ 81,444 KB
実行使用メモリ 73,120 KB
最終ジャッジ日時 2024-03-02 02:21:25
合計ジャッジ時間 5,335 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
66,268 KB
testcase_01 AC 142 ms
72,480 KB
testcase_02 AC 57 ms
68,360 KB
testcase_03 AC 44 ms
55,624 KB
testcase_04 AC 44 ms
55,624 KB
testcase_05 AC 158 ms
70,396 KB
testcase_06 AC 68 ms
68,340 KB
testcase_07 AC 44 ms
57,700 KB
testcase_08 AC 52 ms
64,072 KB
testcase_09 AC 51 ms
64,072 KB
testcase_10 AC 45 ms
55,624 KB
testcase_11 AC 52 ms
64,060 KB
testcase_12 AC 51 ms
63,944 KB
testcase_13 AC 47 ms
57,700 KB
testcase_14 AC 55 ms
66,264 KB
testcase_15 AC 43 ms
55,624 KB
testcase_16 AC 57 ms
66,264 KB
testcase_17 AC 79 ms
70,424 KB
testcase_18 AC 63 ms
68,348 KB
testcase_19 AC 120 ms
72,496 KB
testcase_20 AC 61 ms
68,368 KB
testcase_21 AC 66 ms
68,348 KB
testcase_22 AC 93 ms
70,424 KB
testcase_23 AC 50 ms
64,048 KB
testcase_24 AC 45 ms
55,624 KB
testcase_25 AC 45 ms
55,624 KB
testcase_26 AC 57 ms
66,280 KB
testcase_27 AC 72 ms
68,352 KB
testcase_28 AC 118 ms
72,476 KB
testcase_29 AC 119 ms
72,476 KB
testcase_30 AC 117 ms
72,480 KB
testcase_31 AC 46 ms
57,700 KB
testcase_32 AC 136 ms
72,476 KB
testcase_33 AC 134 ms
72,872 KB
testcase_34 AC 149 ms
72,480 KB
testcase_35 AC 143 ms
72,480 KB
testcase_36 AC 139 ms
72,480 KB
testcase_37 AC 106 ms
72,480 KB
testcase_38 AC 128 ms
72,480 KB
testcase_39 AC 159 ms
72,480 KB
testcase_40 AC 142 ms
72,480 KB
testcase_41 AC 142 ms
73,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353

input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
EI = lambda m: [NLI() for _ in range(m)]


def main():
    N = NI()
    A = NLI()
    M = NI()
    B = NLI()
    B.sort(reverse=True)
    Bok = [[0]*(1<<N) for _ in range(M)]
    for bi in range(M):
        for case in range(1<<N):
            w = 0
            for ai in range(N):
                if (case >> ai) & 1:
                    w += A[ai]
            if B[bi] >= w:
                Bok[bi][case] = 1
    # i個箱を見て、入れたおもちゃがcaseの状態にできるか
    dp = [[0]*(1<<N) for _ in range(M+1)]
    dp[0][0] = 1
    for i in range(M):
        for case in range(1<<N):
            if dp[i][case] == 0:
                continue
            for nc in range(1<<N):
                if case & nc:
                    continue
                if Bok[i][nc] == 0:
                    continue
                dp[i+1][case | nc] = 1
    for bi in range(M+1):
        if dp[bi][-1]:
            print(bi)
            return

    print(-1)


if __name__ == "__main__":
    main()
0