結果

問題 No.50 おもちゃ箱
ユーザー lloyzlloyz
提出日時 2023-10-14 22:54:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 168 ms / 5,000 ms
コード長 606 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 76,704 KB
最終ジャッジ日時 2023-10-14 22:54:43
合計ジャッジ時間 7,385 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
76,120 KB
testcase_01 AC 130 ms
76,492 KB
testcase_02 AC 86 ms
76,360 KB
testcase_03 AC 77 ms
71,008 KB
testcase_04 AC 76 ms
71,516 KB
testcase_05 AC 104 ms
76,412 KB
testcase_06 AC 101 ms
76,496 KB
testcase_07 AC 79 ms
71,136 KB
testcase_08 AC 79 ms
71,168 KB
testcase_09 AC 79 ms
71,008 KB
testcase_10 AC 77 ms
71,424 KB
testcase_11 AC 83 ms
76,324 KB
testcase_12 AC 77 ms
71,256 KB
testcase_13 AC 78 ms
71,132 KB
testcase_14 AC 87 ms
76,384 KB
testcase_15 AC 78 ms
71,300 KB
testcase_16 AC 84 ms
76,516 KB
testcase_17 AC 131 ms
76,444 KB
testcase_18 AC 102 ms
76,508 KB
testcase_19 AC 133 ms
76,428 KB
testcase_20 AC 88 ms
76,388 KB
testcase_21 AC 101 ms
76,552 KB
testcase_22 AC 134 ms
76,276 KB
testcase_23 AC 88 ms
76,140 KB
testcase_24 AC 78 ms
71,412 KB
testcase_25 AC 79 ms
71,344 KB
testcase_26 AC 89 ms
76,524 KB
testcase_27 AC 101 ms
76,704 KB
testcase_28 AC 142 ms
76,528 KB
testcase_29 AC 168 ms
76,604 KB
testcase_30 AC 161 ms
76,532 KB
testcase_31 AC 78 ms
71,436 KB
testcase_32 AC 141 ms
76,668 KB
testcase_33 AC 138 ms
76,556 KB
testcase_34 AC 113 ms
76,668 KB
testcase_35 AC 132 ms
76,424 KB
testcase_36 AC 146 ms
76,492 KB
testcase_37 AC 134 ms
76,580 KB
testcase_38 AC 160 ms
76,424 KB
testcase_39 AC 121 ms
76,488 KB
testcase_40 AC 120 ms
76,496 KB
testcase_41 AC 157 ms
76,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

B.sort(reverse=True)
V = [0 for _ in range(1 << n)]
for bit in range(1 << n):
    for i in range(n):
        if (bit >> i) & 1:
            V[bit] += A[i]
DP = [[False for _ in range(1 << n)] for _ in range(m + 1)]
DP[0][0] = True
for i in range(m):
    for bit1 in range(1 << n):
        for bit2 in range(1 << n):
            if bit1 & bit2 == 0 and DP[i][bit1] and V[bit2] <= B[i]:
                DP[i + 1][bit1 | bit2] = True
    if DP[i + 1][-1]:
        print(i + 1)
        exit()
print(-1)
0