結果

問題 No.50 おもちゃ箱
ユーザー tcltktcltk
提出日時 2021-05-20 00:06:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 252 ms / 5,000 ms
コード長 1,475 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,420 KB
実行使用メモリ 90,404 KB
最終ジャッジ日時 2024-04-18 13:53:41
合計ジャッジ時間 9,244 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
89,036 KB
testcase_01 AC 240 ms
89,872 KB
testcase_02 AC 137 ms
88,632 KB
testcase_03 AC 117 ms
86,484 KB
testcase_04 AC 112 ms
86,616 KB
testcase_05 AC 231 ms
89,784 KB
testcase_06 AC 190 ms
90,152 KB
testcase_07 AC 120 ms
86,788 KB
testcase_08 AC 124 ms
86,604 KB
testcase_09 AC 120 ms
86,804 KB
testcase_10 AC 120 ms
86,760 KB
testcase_11 AC 134 ms
86,604 KB
testcase_12 AC 121 ms
86,476 KB
testcase_13 AC 124 ms
86,820 KB
testcase_14 AC 137 ms
88,724 KB
testcase_15 AC 125 ms
86,864 KB
testcase_16 AC 137 ms
89,008 KB
testcase_17 AC 230 ms
90,304 KB
testcase_18 AC 186 ms
90,000 KB
testcase_19 AC 252 ms
90,000 KB
testcase_20 AC 164 ms
89,292 KB
testcase_21 AC 185 ms
90,152 KB
testcase_22 AC 234 ms
89,888 KB
testcase_23 AC 178 ms
89,944 KB
testcase_24 AC 117 ms
86,804 KB
testcase_25 AC 123 ms
86,956 KB
testcase_26 AC 165 ms
89,400 KB
testcase_27 AC 178 ms
90,224 KB
testcase_28 AC 234 ms
90,404 KB
testcase_29 AC 238 ms
90,104 KB
testcase_30 AC 223 ms
89,848 KB
testcase_31 AC 123 ms
86,532 KB
testcase_32 AC 235 ms
90,172 KB
testcase_33 AC 245 ms
90,108 KB
testcase_34 AC 235 ms
90,044 KB
testcase_35 AC 233 ms
89,944 KB
testcase_36 AC 227 ms
90,132 KB
testcase_37 AC 235 ms
89,740 KB
testcase_38 AC 232 ms
90,372 KB
testcase_39 AC 237 ms
90,156 KB
testcase_40 AC 241 ms
90,116 KB
testcase_41 AC 231 ms
90,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """2
# 2 3
# 1
# 5
# """
# sys.stdin = io.StringIO(_INPUT)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    M = int(input())
    B = list(map(int, input().split()))
    B.sort(reverse=True)

    dp = [10**10] * (1<<N)
    dp[0] = 0
    for s in range(1<<N):
        for t in range(1<<N):
            if s & t:
                continue
            s1 = s | t
            size = sum(A[i] for i in range(N) if t & (1<<i))
            if dp[s] < M and size <= B[dp[s]]:
                dp[s1] = min(dp[s1], dp[s] + 1)
    ans = dp[(1<<N)-1]
    if ans == 10**10:
        print(-1)
    else:
        print(ans)

    # ans = 100
    # for pat in itertools.permutations(A):
    #     i = 0
    #     cap = B[0]
    #     ok = True
    #     for item in pat:
    #         if item <= cap:
    #             cap -= item
    #         else:
    #             i += 1
    #             if i >= M or B[i] < item:
    #                 ok = False
    #                 break
    #             cap = B[i] - item
    #     if ok:
    #         ans = min(ans, i+1)

    # if ans == 100:
    #     print(-1)
    # else:
    #     print(ans)

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