結果

問題 No.50 おもちゃ箱
ユーザー Mao-betaMao-beta
提出日時 2024-03-02 02:12:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,199 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 16,788 KB
最終ジャッジ日時 2024-03-02 02:12:42
合計ジャッジ時間 7,546 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 352 ms
10,240 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
権限があれば一括ダウンロードができます

ソースコード

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)
    ans = [M+1]

    def dfs(case, bi):
        if case == (1<<N)-1:
            ans[0] = min(ans[0], bi+1)
            return 

        if bi >= M:
            return

        for i in range(N):
            if (case >> i) & 1:
                continue
            if A[i] > B[bi]:
                continue
            B[bi] -= A[i]
            dfs(case | (1<<i), bi)
            B[bi] += A[i]

        dfs(case, bi+1)

    dfs(0, 0)
    if ans[0] == M+1:
        print(-1)
    else:
        print(ans[0])


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