結果

問題 No.50 おもちゃ箱
ユーザー roarisroaris
提出日時 2020-12-09 18:34:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 84 ms / 5,000 ms
コード長 611 bytes
コンパイル時間 1,071 ms
コンパイル使用メモリ 81,660 KB
実行使用メモリ 68,392 KB
最終ジャッジ日時 2023-10-19 05:06:29
合計ジャッジ時間 4,197 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
59,676 KB
testcase_01 AC 81 ms
68,392 KB
testcase_02 AC 48 ms
61,756 KB
testcase_03 AC 39 ms
53,408 KB
testcase_04 AC 38 ms
53,408 KB
testcase_05 AC 52 ms
62,164 KB
testcase_06 AC 64 ms
68,332 KB
testcase_07 AC 39 ms
53,408 KB
testcase_08 AC 40 ms
53,408 KB
testcase_09 AC 39 ms
53,408 KB
testcase_10 AC 39 ms
53,408 KB
testcase_11 AC 40 ms
53,408 KB
testcase_12 AC 39 ms
53,408 KB
testcase_13 AC 38 ms
53,408 KB
testcase_14 AC 48 ms
61,756 KB
testcase_15 AC 40 ms
53,408 KB
testcase_16 AC 49 ms
61,756 KB
testcase_17 AC 66 ms
68,384 KB
testcase_18 AC 61 ms
66,256 KB
testcase_19 AC 68 ms
66,328 KB
testcase_20 AC 53 ms
63,904 KB
testcase_21 AC 62 ms
66,276 KB
testcase_22 AC 68 ms
66,336 KB
testcase_23 AC 50 ms
62,088 KB
testcase_24 AC 39 ms
53,408 KB
testcase_25 AC 39 ms
53,408 KB
testcase_26 AC 50 ms
61,788 KB
testcase_27 AC 62 ms
66,264 KB
testcase_28 AC 77 ms
68,392 KB
testcase_29 AC 84 ms
68,392 KB
testcase_30 AC 71 ms
66,312 KB
testcase_31 AC 38 ms
53,408 KB
testcase_32 AC 69 ms
66,328 KB
testcase_33 AC 68 ms
66,312 KB
testcase_34 AC 65 ms
66,492 KB
testcase_35 AC 70 ms
68,392 KB
testcase_36 AC 70 ms
66,328 KB
testcase_37 AC 68 ms
66,312 KB
testcase_38 AC 75 ms
66,312 KB
testcase_39 AC 66 ms
66,328 KB
testcase_40 AC 67 ms
68,392 KB
testcase_41 AC 73 ms
66,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int, input().split()))
M = int(input())
B = list(map(int, input().split()))
B.sort(reverse=True)
score = [0]*(1<<N)

for S in range(1<<N):
    for i in range(N):
        if (S>>i)&1:
            score[S] += A[i]
            
dp = [[False]*(1<<N) for _ in range(M+1)]
dp[0][0] = True

for i in range(M):
    for S in range(1<<N):
        T = S
        
        while True:
            dp[i+1][S] |= dp[i][T] and B[i]>=score[S-T]
            T = (T-1)&S
            
            if T==S:
                break

    if dp[i+1][-1]:
        print(i+1)
        break
else:
    print(-1)
0