結果

問題 No.50 おもちゃ箱
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-01-01 20:41:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 117 ms / 5,000 ms
コード長 591 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,180 KB
実行使用メモリ 76,188 KB
最終ジャッジ日時 2024-04-18 19:51:59
合計ジャッジ時間 4,189 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
63,596 KB
testcase_01 AC 72 ms
73,444 KB
testcase_02 AC 44 ms
62,740 KB
testcase_03 AC 38 ms
52,572 KB
testcase_04 AC 35 ms
52,440 KB
testcase_05 AC 56 ms
67,984 KB
testcase_06 AC 58 ms
67,704 KB
testcase_07 AC 33 ms
52,872 KB
testcase_08 AC 34 ms
53,092 KB
testcase_09 AC 36 ms
52,964 KB
testcase_10 AC 36 ms
52,528 KB
testcase_11 AC 42 ms
60,376 KB
testcase_12 AC 36 ms
52,676 KB
testcase_13 AC 34 ms
53,324 KB
testcase_14 AC 42 ms
62,524 KB
testcase_15 AC 32 ms
52,184 KB
testcase_16 AC 48 ms
64,628 KB
testcase_17 AC 68 ms
72,628 KB
testcase_18 AC 57 ms
68,384 KB
testcase_19 AC 89 ms
75,840 KB
testcase_20 AC 50 ms
63,944 KB
testcase_21 AC 60 ms
70,132 KB
testcase_22 AC 80 ms
75,732 KB
testcase_23 AC 39 ms
60,500 KB
testcase_24 AC 33 ms
52,816 KB
testcase_25 AC 34 ms
52,732 KB
testcase_26 AC 47 ms
61,652 KB
testcase_27 AC 68 ms
72,784 KB
testcase_28 AC 97 ms
75,764 KB
testcase_29 AC 117 ms
76,188 KB
testcase_30 AC 96 ms
75,852 KB
testcase_31 AC 34 ms
52,420 KB
testcase_32 AC 87 ms
75,744 KB
testcase_33 AC 79 ms
75,464 KB
testcase_34 AC 63 ms
70,672 KB
testcase_35 AC 90 ms
76,008 KB
testcase_36 AC 87 ms
75,848 KB
testcase_37 AC 78 ms
75,520 KB
testcase_38 AC 105 ms
75,768 KB
testcase_39 AC 67 ms
73,512 KB
testcase_40 AC 64 ms
72,436 KB
testcase_41 AC 114 ms
75,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

dp = [0]*(1<<n)
dp[0] = 1
for i,b in enumerate(B,1):
    for bit in range(1<<n)[::-1]:
        if dp[bit] == 0:
            continue
        
        for mask in range(1<<n):
            if bit & mask:
                continue
            count = 0
            for j in range(n):
                if mask >> j & 1:
                    count += A[j]
            if count <= b:
                dp[bit^mask] = 1
    if dp[-1]:
        print(i)
        exit()
print(-1)
0