結果

問題 No.50 おもちゃ箱
ユーザー vwxyzvwxyz
提出日時 2024-02-27 09:33:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,070 ms / 5,000 ms
コード長 446 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-02-27 09:33:34
合計ジャッジ時間 15,954 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
9,984 KB
testcase_01 AC 560 ms
9,984 KB
testcase_02 AC 32 ms
9,984 KB
testcase_03 AC 27 ms
9,984 KB
testcase_04 AC 27 ms
9,984 KB
testcase_05 AC 247 ms
9,984 KB
testcase_06 AC 182 ms
9,984 KB
testcase_07 AC 27 ms
9,984 KB
testcase_08 AC 27 ms
9,984 KB
testcase_09 AC 27 ms
9,984 KB
testcase_10 AC 26 ms
9,984 KB
testcase_11 AC 27 ms
9,984 KB
testcase_12 AC 27 ms
9,984 KB
testcase_13 AC 27 ms
9,984 KB
testcase_14 AC 31 ms
9,984 KB
testcase_15 AC 27 ms
9,984 KB
testcase_16 AC 30 ms
9,984 KB
testcase_17 AC 635 ms
9,984 KB
testcase_18 AC 210 ms
9,984 KB
testcase_19 AC 644 ms
9,984 KB
testcase_20 AC 43 ms
9,984 KB
testcase_21 AC 187 ms
9,984 KB
testcase_22 AC 632 ms
9,984 KB
testcase_23 AC 58 ms
9,984 KB
testcase_24 AC 32 ms
9,984 KB
testcase_25 AC 29 ms
9,984 KB
testcase_26 AC 38 ms
9,984 KB
testcase_27 AC 158 ms
9,984 KB
testcase_28 AC 749 ms
9,984 KB
testcase_29 AC 1,070 ms
9,984 KB
testcase_30 AC 1,060 ms
9,984 KB
testcase_31 AC 28 ms
9,984 KB
testcase_32 AC 745 ms
9,984 KB
testcase_33 AC 752 ms
9,984 KB
testcase_34 AC 348 ms
9,984 KB
testcase_35 AC 630 ms
9,984 KB
testcase_36 AC 742 ms
9,984 KB
testcase_37 AC 632 ms
9,984 KB
testcase_38 AC 1,052 ms
9,984 KB
testcase_39 AC 452 ms
9,984 KB
testcase_40 AC 448 ms
9,984 KB
testcase_41 AC 957 ms
9,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
A=list(map(int,input().split()))
M=int(input())
B=list(map(int,input().split()))
B.sort(reverse=True)
dp=[False]*(1<<N)
dp[0]=True
ans=0
for b in B:
    for bit in range((1<<N)-1,-1,-1):
        bit_=bit
        while bit_:
            if sum(A[i] for i in range(N) if bit_&1<<i)<=b:
                dp[bit]|=dp[bit^bit_]
            bit_-=1
            bit_&=bit
    ans+=1
    if dp[-1]:
        break
else:
    ans=-1
print(ans)
0