結果
問題 | No.617 Nafmo、買い出しに行く |
ユーザー | kichirb3 |
提出日時 | 2018-03-02 13:36:55 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 1,415 bytes |
コンパイル時間 | 672 ms |
コンパイル使用メモリ | 10,844 KB |
実行使用メモリ | 8,436 KB |
最終ジャッジ日時 | 2023-08-30 22:19:23 |
合計ジャッジ時間 | 1,823 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 18 ms
8,344 KB |
testcase_01 | AC | 16 ms
8,232 KB |
testcase_02 | AC | 19 ms
8,300 KB |
testcase_03 | AC | 20 ms
8,216 KB |
testcase_04 | AC | 16 ms
8,224 KB |
testcase_05 | AC | 19 ms
8,220 KB |
testcase_06 | AC | 22 ms
8,408 KB |
testcase_07 | AC | 22 ms
8,292 KB |
testcase_08 | AC | 15 ms
8,364 KB |
testcase_09 | AC | 15 ms
8,220 KB |
testcase_10 | AC | 23 ms
8,304 KB |
testcase_11 | AC | 23 ms
8,296 KB |
testcase_12 | AC | 23 ms
8,416 KB |
testcase_13 | AC | 23 ms
8,436 KB |
testcase_14 | AC | 23 ms
8,312 KB |
testcase_15 | AC | 23 ms
8,376 KB |
testcase_16 | AC | 22 ms
8,304 KB |
testcase_17 | AC | 22 ms
8,312 KB |
testcase_18 | AC | 16 ms
8,356 KB |
testcase_19 | AC | 16 ms
8,256 KB |
testcase_20 | AC | 17 ms
8,292 KB |
testcase_21 | AC | 16 ms
8,160 KB |
ソースコード
# -*- coding: utf-8 -*- """ No.617 Nafmo、買い出しに行く https://yukicoder.me/problems/no/617 """ import sys from sys import stdin from itertools import compress from bisect import bisect_right input = stdin.readline def main(): N, K = map(int, input().split()) items = [] for i in range(N): items.append(int(input())) # アイテムを半分に分ける (後半は空の可能性もあり) items_a = items[:10] items_b = items[10:] # 前半のアイテムを選択した場合の重さの組み合わせを列挙 total_a = [] for i in range(2**len(items_a)): mask = [int(x) for x in list(bin(i)[2:].zfill(len(items_a)))] res = compress(items_a, mask) total_a.append(sum(res)) # 後半のアイテムを選択した場合の重さの組み合わせを列挙 total_b = [] for i in range(2**len(items_b)): mask = [int(x) for x in list(bin(i)[2:].zfill(len(items_b)))] res = compress(items_b, mask) total_b.append(sum(res)) # 前半と後半の重さの組み合わせから、K以内での最大値を求める total_a.sort(); total_b.sort(); total_max = 0; for a in total_a: i = bisect_right(total_b, K-a) total = a + total_b[i-1] if total <= K: total_max = max(total, total_max) print(total_max) if __name__ == '__main__': main()