結果

問題 No.50 おもちゃ箱
ユーザー しらっ亭しらっ亭
提出日時 2015-07-09 05:16:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,179 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-17 22:50:28
合計ジャッジ時間 2,356 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,880 KB
testcase_01 AC 32 ms
10,880 KB
testcase_02 AC 31 ms
10,880 KB
testcase_03 AC 31 ms
10,880 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 33 ms
10,880 KB
testcase_06 AC 29 ms
10,880 KB
testcase_07 AC 29 ms
10,880 KB
testcase_08 AC 29 ms
10,880 KB
testcase_09 AC 29 ms
10,880 KB
testcase_10 AC 30 ms
11,008 KB
testcase_11 AC 29 ms
10,880 KB
testcase_12 AC 30 ms
10,880 KB
testcase_13 AC 29 ms
10,880 KB
testcase_14 AC 30 ms
10,880 KB
testcase_15 AC 31 ms
10,880 KB
testcase_16 AC 31 ms
10,880 KB
testcase_17 AC 29 ms
10,880 KB
testcase_18 AC 29 ms
11,008 KB
testcase_19 AC 32 ms
10,880 KB
testcase_20 AC 29 ms
10,880 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 29 ms
10,880 KB
testcase_24 AC 29 ms
10,880 KB
testcase_25 AC 29 ms
10,880 KB
testcase_26 AC 29 ms
10,880 KB
testcase_27 AC 31 ms
10,880 KB
testcase_28 AC 33 ms
10,880 KB
testcase_29 AC 33 ms
11,008 KB
testcase_30 AC 33 ms
10,880 KB
testcase_31 AC 29 ms
11,008 KB
testcase_32 AC 34 ms
10,880 KB
testcase_33 AC 33 ms
10,880 KB
testcase_34 AC 33 ms
10,880 KB
testcase_35 AC 34 ms
10,880 KB
testcase_36 AC 34 ms
10,880 KB
testcase_37 AC 33 ms
10,880 KB
testcase_38 AC 33 ms
10,880 KB
testcase_39 AC 33 ms
10,880 KB
testcase_40 AC 33 ms
10,880 KB
testcase_41 AC 33 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(A, B):
    B.sort(reverse=True)
    l = len(A)

    DP = [(100, 100)] * (1 << l)
    DP[0] = (0, 0)

    for i in range(0, (1 << l) - 1):
        u1, u2 = DP[i]
        if u1 == 100:
            return -1
        b = B[u1]
        for j in range(len(A)):
            a = A[j]
            j1 = 1 << j
            if i & j1 == 0:
                if b - u2 > a:
                    n = (u1, u2 + a)
                elif b - u2 == a:
                    n = (u1 + 1, 0)
                else:
                    for k in range(u1 + 1, len(B)):
                        if B[k] > a:
                            n = (k, a)
                            break
                        elif B[k] == a:
                            n = (k + 1, 0)
                            break
                    else:
                        continue
                DP[i | j1] = min(DP[i | j1], n)

    if DP[-1] == (100, 100):
        return -1
    return DP[-1][0] + (1 if DP[-1][1] else 0)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    M = int(input())
    B = list(map(int, input().split()))

    print(solve(A, B))


if __name__ == '__main__':
    main()
0