結果
問題 | No.2370 He ate many cakes |
ユーザー | meruuu61779999 |
提出日時 | 2023-06-29 23:22:48 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 926 ms / 2,000 ms |
コード長 | 837 bytes |
コンパイル時間 | 349 ms |
コンパイル使用メモリ | 86,784 KB |
実行使用メモリ | 87,744 KB |
最終ジャッジ日時 | 2023-09-20 18:22:00 |
合計ジャッジ時間 | 8,446 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 79 ms
71,512 KB |
testcase_01 | AC | 80 ms
71,128 KB |
testcase_02 | AC | 77 ms
71,340 KB |
testcase_03 | AC | 458 ms
83,304 KB |
testcase_04 | AC | 79 ms
71,372 KB |
testcase_05 | AC | 79 ms
71,344 KB |
testcase_06 | AC | 78 ms
71,532 KB |
testcase_07 | AC | 78 ms
71,356 KB |
testcase_08 | AC | 77 ms
71,356 KB |
testcase_09 | AC | 78 ms
71,352 KB |
testcase_10 | AC | 192 ms
80,372 KB |
testcase_11 | AC | 296 ms
82,972 KB |
testcase_12 | AC | 500 ms
81,708 KB |
testcase_13 | AC | 718 ms
87,012 KB |
testcase_14 | AC | 325 ms
83,156 KB |
testcase_15 | AC | 926 ms
86,084 KB |
testcase_16 | AC | 887 ms
82,596 KB |
testcase_17 | AC | 880 ms
87,744 KB |
testcase_18 | AC | 427 ms
79,188 KB |
testcase_19 | AC | 86 ms
75,960 KB |
ソースコード
from itertools import product from heapq import heappop, heappush # lst内ケーキの選び方すべてにおける嬉しさのリスト def H(lst): ret = [] for pro in product((0, 1), repeat=len(lst)): val = 0 for el, pr in zip(lst, pro): if pr: val += el ret.append(val) return ret N, K = map(int, input().split()) A = list(map(int, input().split())) mid = N // 2 A_left, A_right = A[:mid], A[mid:] C, D = H(A_left), H(A_right) D.sort(reverse=True) def f(i, j): return C[i] + D[j] hque = [] # タプル(-f(i,j),i,j)を入れる。 for i in range(len(C)): heappush(hque, (-f(i, 0), i, 0)) for _ in range(K - 1): m_val, i, j = heappop(hque) if j + 1 < len(D): heappush(hque, (-f(i, j + 1), i, j + 1)) m_val, i, j = heappop(hque) ans = -m_val print(ans)