結果

問題 No.50 おもちゃ箱
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-07-18 20:56:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,771 ms / 5,000 ms
コード長 744 bytes
コンパイル時間 296 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 76,684 KB
最終ジャッジ日時 2023-09-08 04:31:41
合計ジャッジ時間 20,762 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
75,904 KB
testcase_01 AC 920 ms
76,384 KB
testcase_02 AC 79 ms
75,784 KB
testcase_03 AC 71 ms
71,432 KB
testcase_04 AC 71 ms
71,336 KB
testcase_05 AC 537 ms
76,420 KB
testcase_06 AC 191 ms
76,368 KB
testcase_07 AC 71 ms
71,444 KB
testcase_08 AC 72 ms
71,224 KB
testcase_09 AC 70 ms
71,328 KB
testcase_10 AC 69 ms
71,560 KB
testcase_11 AC 74 ms
75,260 KB
testcase_12 AC 69 ms
71,544 KB
testcase_13 AC 70 ms
71,416 KB
testcase_14 AC 79 ms
76,172 KB
testcase_15 AC 72 ms
71,444 KB
testcase_16 AC 79 ms
76,484 KB
testcase_17 AC 920 ms
76,472 KB
testcase_18 AC 124 ms
76,344 KB
testcase_19 AC 844 ms
76,348 KB
testcase_20 AC 75 ms
76,076 KB
testcase_21 AC 133 ms
76,364 KB
testcase_22 AC 1,165 ms
76,264 KB
testcase_23 AC 103 ms
76,544 KB
testcase_24 AC 72 ms
71,320 KB
testcase_25 AC 71 ms
71,324 KB
testcase_26 AC 79 ms
75,956 KB
testcase_27 AC 133 ms
76,396 KB
testcase_28 AC 850 ms
76,384 KB
testcase_29 AC 846 ms
76,240 KB
testcase_30 AC 620 ms
76,440 KB
testcase_31 AC 71 ms
71,344 KB
testcase_32 AC 780 ms
76,460 KB
testcase_33 AC 719 ms
76,680 KB
testcase_34 AC 713 ms
76,476 KB
testcase_35 AC 825 ms
76,664 KB
testcase_36 AC 1,771 ms
76,684 KB
testcase_37 AC 725 ms
76,492 KB
testcase_38 AC 822 ms
76,488 KB
testcase_39 AC 761 ms
76,660 KB
testcase_40 AC 1,266 ms
76,540 KB
testcase_41 AC 894 ms
76,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

import itertools


IMPOSSIBLE = -1


def main():
    num_items = int(input())
    items = map(int, input().split())
    num_boxes = int(input())
    boxes_base = sorted(map(int, input().split()), reverse=True)
    ans = num_boxes + 1
    for items_perm in itertools.permutations(items):
        boxes = boxes_base[:]
        item_idx = box_idx = 0
        while item_idx < num_items and box_idx < num_boxes:
            if boxes[box_idx] >= items_perm[item_idx]:
                boxes[box_idx] -= items_perm[item_idx]
                item_idx += 1
            else:
                box_idx += 1
        ans = min(ans, box_idx + 1)
    print(ans if ans <= num_boxes else IMPOSSIBLE)


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