結果

問題 No.50 おもちゃ箱
ユーザー szkhtsszkhts
提出日時 2023-10-08 08:37:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 492 ms / 5,000 ms
コード長 670 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 8,368 KB
最終ジャッジ日時 2023-10-08 08:37:56
合計ジャッジ時間 4,932 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,228 KB
testcase_01 AC 95 ms
8,344 KB
testcase_02 AC 16 ms
8,160 KB
testcase_03 AC 16 ms
8,160 KB
testcase_04 AC 15 ms
7,968 KB
testcase_05 AC 492 ms
8,184 KB
testcase_06 AC 43 ms
8,324 KB
testcase_07 AC 14 ms
8,276 KB
testcase_08 AC 14 ms
8,284 KB
testcase_09 AC 15 ms
8,184 KB
testcase_10 AC 15 ms
8,352 KB
testcase_11 AC 15 ms
8,288 KB
testcase_12 AC 15 ms
8,224 KB
testcase_13 AC 15 ms
8,300 KB
testcase_14 AC 16 ms
8,332 KB
testcase_15 AC 15 ms
8,304 KB
testcase_16 AC 15 ms
8,320 KB
testcase_17 AC 58 ms
7,920 KB
testcase_18 AC 28 ms
7,788 KB
testcase_19 AC 76 ms
8,220 KB
testcase_20 AC 18 ms
8,220 KB
testcase_21 AC 36 ms
7,816 KB
testcase_22 AC 70 ms
7,856 KB
testcase_23 AC 17 ms
7,968 KB
testcase_24 AC 14 ms
7,860 KB
testcase_25 AC 16 ms
7,912 KB
testcase_26 AC 18 ms
8,196 KB
testcase_27 AC 51 ms
8,348 KB
testcase_28 AC 141 ms
8,276 KB
testcase_29 AC 150 ms
7,788 KB
testcase_30 AC 52 ms
8,280 KB
testcase_31 AC 15 ms
8,196 KB
testcase_32 AC 69 ms
8,352 KB
testcase_33 AC 76 ms
8,232 KB
testcase_34 AC 191 ms
8,296 KB
testcase_35 AC 101 ms
8,180 KB
testcase_36 AC 77 ms
8,296 KB
testcase_37 AC 88 ms
8,368 KB
testcase_38 AC 66 ms
7,788 KB
testcase_39 AC 193 ms
8,268 KB
testcase_40 AC 124 ms
8,320 KB
testcase_41 AC 154 ms
8,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
b.sort(reverse=True)

dp1 = [False] * (1 << 10)
dp2 = [False] * (1 << 10)

dp1[0] = True

for i in range(m):
    for j in range(1 << n):
        c = 0
        for k in range(n):
            if (j >> k) % 2 == 0:
                continue
            c += a[k]
        if c > b[i]:
            continue
        
        for k in range((1 << n) - 1, -1, -1):
            dp2[j | k] |= dp1[k]
            
    for k in range((1 << n) - 1, -1, -1):
        dp1[k] = dp2[k]
    if dp1[(1 << n) - 1]:
        print(i + 1)
        sys.exit(0)
       
print(-1)
0