結果

問題 No.50 おもちゃ箱
ユーザー ckawatakckawatak
提出日時 2019-01-14 19:43:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 846 bytes
コンパイル時間 926 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 77,060 KB
最終ジャッジ日時 2023-09-04 16:17:44
合計ジャッジ時間 7,645 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 78 ms
71,532 KB
testcase_04 AC 78 ms
71,356 KB
testcase_05 AC 203 ms
76,920 KB
testcase_06 AC 107 ms
77,060 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 108 ms
76,780 KB
testcase_18 AC 96 ms
76,984 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 104 ms
76,792 KB
testcase_22 AC 116 ms
76,888 KB
testcase_23 AC 83 ms
76,612 KB
testcase_24 AC 75 ms
71,424 KB
testcase_25 AC 75 ms
71,396 KB
testcase_26 AC 89 ms
76,916 KB
testcase_27 AC 110 ms
76,944 KB
testcase_28 WA -
testcase_29 AC 171 ms
76,656 KB
testcase_30 AC 102 ms
77,000 KB
testcase_31 AC 75 ms
71,348 KB
testcase_32 WA -
testcase_33 AC 170 ms
76,836 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 149 ms
76,900 KB
testcase_39 WA -
testcase_40 AC 182 ms
76,876 KB
testcase_41 AC 176 ms
76,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int, input().split(' ')))
M = int(input())
B = list(map(int, input().split(' ')))

sum = [0 for _ in range(1<<N)]
for i in range(1<<N):
    for j in range(N):
        if i & (1<<j):
            sum[i] = sum[i] + A[j]

# dp[i][j]: minimum number of boxes
# when boxes are used until i to accommodate j collection of toys
dp = []
for i in range(M+1):
    dp.append([float('inf') for _ in range(1<<N)])

dp[0][0] = 0

for i in range(M):
    for j in range(1<<N):
        if dp[i][j] == float('inf'):
            continue
        for k in range(1<<N):
            if (j & k == 0) and (sum[k] <= B[i]):     
                dp[i+1][j|k] = min(dp[i+1][j|k], dp[i][j]+1)

answer = float('inf')
for i in range(M+1):
    answer = min(answer, dp[i][(1<<N)-1])

if answer != float('inf'):
    print(answer)
else:
    print(-1)
0