結果

問題 No.50 おもちゃ箱
ユーザー しらっ亭しらっ亭
提出日時 2015-07-09 05:03:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,134 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 11,004 KB
実行使用メモリ 8,408 KB
最終ジャッジ日時 2023-09-22 09:39:44
合計ジャッジ時間 2,238 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 18 ms
8,216 KB
testcase_02 WA -
testcase_03 AC 15 ms
8,288 KB
testcase_04 AC 16 ms
8,160 KB
testcase_05 AC 17 ms
8,320 KB
testcase_06 AC 16 ms
8,196 KB
testcase_07 WA -
testcase_08 AC 15 ms
8,292 KB
testcase_09 AC 15 ms
8,228 KB
testcase_10 AC 15 ms
8,288 KB
testcase_11 AC 15 ms
8,124 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 15 ms
8,164 KB
testcase_15 AC 16 ms
8,292 KB
testcase_16 WA -
testcase_17 RE -
testcase_18 RE -
testcase_19 AC 17 ms
8,272 KB
testcase_20 AC 16 ms
8,288 KB
testcase_21 AC 16 ms
8,320 KB
testcase_22 AC 17 ms
8,248 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 15 ms
8,348 KB
testcase_26 WA -
testcase_27 AC 16 ms
8,276 KB
testcase_28 WA -
testcase_29 AC 17 ms
8,344 KB
testcase_30 AC 18 ms
8,404 KB
testcase_31 AC 16 ms
8,160 KB
testcase_32 AC 17 ms
8,320 KB
testcase_33 WA -
testcase_34 AC 17 ms
8,260 KB
testcase_35 WA -
testcase_36 AC 18 ms
8,184 KB
testcase_37 AC 17 ms
8,224 KB
testcase_38 AC 17 ms
8,220 KB
testcase_39 AC 17 ms
8,408 KB
testcase_40 AC 17 ms
8,188 KB
testcase_41 AC 17 ms
8,408 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]
        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