結果

問題 No.50 おもちゃ箱
ユーザー brthyyjpbrthyyjp
提出日時 2021-10-01 00:47:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 655 bytes
コンパイル時間 1,027 ms
コンパイル使用メモリ 87,020 KB
実行使用メモリ 76,796 KB
最終ジャッジ日時 2023-09-25 06:40:11
合計ジャッジ時間 6,527 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
76,220 KB
testcase_01 AC 90 ms
76,740 KB
testcase_02 AC 79 ms
75,828 KB
testcase_03 AC 71 ms
71,404 KB
testcase_04 AC 72 ms
71,444 KB
testcase_05 AC 128 ms
76,636 KB
testcase_06 AC 89 ms
76,568 KB
testcase_07 AC 69 ms
71,120 KB
testcase_08 AC 72 ms
71,328 KB
testcase_09 AC 70 ms
71,428 KB
testcase_10 AC 71 ms
71,396 KB
testcase_11 AC 76 ms
76,000 KB
testcase_12 AC 72 ms
71,400 KB
testcase_13 AC 70 ms
71,456 KB
testcase_14 AC 78 ms
76,156 KB
testcase_15 AC 71 ms
71,316 KB
testcase_16 AC 76 ms
76,012 KB
testcase_17 AC 88 ms
76,608 KB
testcase_18 AC 85 ms
76,244 KB
testcase_19 AC 91 ms
76,684 KB
testcase_20 AC 79 ms
76,320 KB
testcase_21 AC 90 ms
76,680 KB
testcase_22 AC 89 ms
76,696 KB
testcase_23 AC 82 ms
76,628 KB
testcase_24 AC 72 ms
71,416 KB
testcase_25 AC 73 ms
71,316 KB
testcase_26 AC 79 ms
76,188 KB
testcase_27 AC 93 ms
76,564 KB
testcase_28 AC 96 ms
76,796 KB
testcase_29 AC 97 ms
76,476 KB
testcase_30 AC 96 ms
76,364 KB
testcase_31 AC 75 ms
71,664 KB
testcase_32 AC 98 ms
76,440 KB
testcase_33 AC 94 ms
76,660 KB
testcase_34 AC 101 ms
76,372 KB
testcase_35 AC 95 ms
76,684 KB
testcase_36 AC 97 ms
76,484 KB
testcase_37 AC 94 ms
76,748 KB
testcase_38 AC 97 ms
76,720 KB
testcase_39 AC 99 ms
76,556 KB
testcase_40 AC 101 ms
76,660 KB
testcase_41 AC 103 ms
76,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(map(int, input().split()))
m = int(input())
B = list(map(int, input().split()))

B.reverse()
C = [[] for j in range(m)]
for mask in range(1<<n):
    x = 0
    for i in range(n):
        if (mask>>i)&1:
            x += A[i]
    for j in range(m):
        if x <= B[j]:
            C[j].append(mask)
INF =10**18
dp = [INF]*(1<<n)
dp[0] = 0
for j in range(m):
    nx = [INF]*(1<<n)
    for mask1 in range(1<<n):
        nx[mask1] = dp[mask1]
    for mask1 in range(1<<n):
        for mask2 in C[j]:
            nx[mask1|mask2] = min(nx[mask1|mask2], dp[mask1]+1)
    dp = nx
if dp[-1] != INF:
    print(dp[-1])
else:
    print(-1)
0