結果

問題 No.50 おもちゃ箱
ユーザー chocoruskchocorusk
提出日時 2020-09-10 04:27:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 920 ms / 5,000 ms
コード長 910 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 82,112 KB
実行使用メモリ 85,348 KB
最終ジャッジ日時 2024-12-17 22:17:06
合計ジャッジ時間 14,148 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,344 KB
testcase_01 AC 727 ms
85,164 KB
testcase_02 AC 62 ms
68,384 KB
testcase_03 AC 37 ms
54,124 KB
testcase_04 AC 36 ms
53,264 KB
testcase_05 AC 279 ms
84,860 KB
testcase_06 AC 96 ms
76,960 KB
testcase_07 AC 37 ms
52,652 KB
testcase_08 AC 56 ms
66,116 KB
testcase_09 AC 54 ms
65,620 KB
testcase_10 AC 38 ms
52,592 KB
testcase_11 AC 54 ms
66,264 KB
testcase_12 AC 58 ms
67,972 KB
testcase_13 AC 53 ms
65,684 KB
testcase_14 AC 56 ms
65,868 KB
testcase_15 AC 45 ms
61,524 KB
testcase_16 AC 53 ms
64,644 KB
testcase_17 AC 105 ms
77,280 KB
testcase_18 AC 90 ms
77,068 KB
testcase_19 AC 281 ms
78,800 KB
testcase_20 AC 69 ms
68,116 KB
testcase_21 AC 76 ms
75,192 KB
testcase_22 AC 135 ms
77,152 KB
testcase_23 AC 56 ms
67,584 KB
testcase_24 AC 38 ms
54,808 KB
testcase_25 AC 37 ms
52,936 KB
testcase_26 AC 53 ms
64,092 KB
testcase_27 AC 106 ms
77,136 KB
testcase_28 AC 823 ms
85,208 KB
testcase_29 AC 820 ms
85,016 KB
testcase_30 AC 630 ms
84,860 KB
testcase_31 AC 38 ms
53,500 KB
testcase_32 AC 722 ms
85,072 KB
testcase_33 AC 718 ms
84,976 KB
testcase_34 AC 569 ms
84,828 KB
testcase_35 AC 817 ms
85,348 KB
testcase_36 AC 792 ms
85,228 KB
testcase_37 AC 820 ms
84,920 KB
testcase_38 AC 817 ms
85,076 KB
testcase_39 AC 662 ms
85,084 KB
testcase_40 AC 425 ms
84,896 KB
testcase_41 AC 920 ms
85,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

import itertools
n=int(readline())
a=list(map(int, readline().split()))
m=int(readline())
b=list(map(int, readline().split()))
ok=[[False]*(1<<n) for _ in range(m)]
for i in range(1<<n):
    s=sum(x for j, x in enumerate(a) if i&(1<<j))
    for j, y in enumerate(b):
        if s<=y:
            ok[j][i]=True
dp=[False]*(1<<(n+m))
dp[0]=True
for i in range(1<<(n+m)):
    j0=m
    for j in range(m):
        if i&(1<<j):
            j0=j
            break
    else:
        continue
    mask=i&(((1<<n)-1)<<m)
    k=mask
    while k:
        if ok[j0][k>>m] and dp[i^k^(1<<j0)]:
            dp[i]=True
            break
        k=(k-1)&mask
def popcount(x):
    return bin(x).count('1')
ans=[popcount(i) for i in range(1<<m) if dp[(((1<<n)-1)<<m)^i]]
if ans:
    print(min(ans))
else:
    print(-1)
0