結果

問題 No.1248 Kth Sum
ユーザー pigeonpigeon
提出日時 2020-10-22 18:18:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,218 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 11,088 KB
実行使用メモリ 45,504 KB
最終ジャッジ日時 2023-09-28 14:45:17
合計ジャッジ時間 4,732 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,460 KB
testcase_01 AC 17 ms
8,012 KB
testcase_02 AC 17 ms
8,084 KB
testcase_03 AC 18 ms
8,248 KB
testcase_04 AC 17 ms
8,080 KB
testcase_05 AC 18 ms
8,136 KB
testcase_06 AC 18 ms
8,096 KB
testcase_07 AC 18 ms
8,120 KB
testcase_08 AC 17 ms
8,056 KB
testcase_09 AC 18 ms
8,244 KB
testcase_10 AC 18 ms
8,148 KB
testcase_11 AC 17 ms
8,092 KB
testcase_12 AC 20 ms
8,192 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

N, K = [ int(a) for a in input().split(' ') ]
alist = [ int(a) for a in input().split(' ') ]

def is_valid(num_subl, inds):
    inds = sorted(inds)
    prev = -1
    for i in range(num_subl):
        start = max(prev+1, K*(i+1)-1)
        end = min(start+(num_subl-i-1)*(K-1)+ (N-num_subl*K if i > 0 else 0), N-(num_subl-i-1)-1)
        if inds[i] not in range(start,end+1):
            return False
        prev = inds[i]
    return True

agenda = []
enumed = list(enumerate(alist))
sortedl = sorted(enumed, key=lambda p:p[1])
for num_subl in range(1,N//K+1):
    if num_subl > 1:
        if min(agenda) < sum([ p[1] for p in sortedl[:num_subl] ]):
            break
    queue = []
    heapq.heappush(queue,(sum([ p[1] for p in sortedl[:num_subl] ]), tuple(sortedl)))
    while queue:
        sumc, checking = heapq.heappop(queue)
        if is_valid(num_subl, [ p[0] for p in checking[:num_subl] ]):
            agenda.append(sumc)
            break
        if len(checking)>num_subl:
            for i in range(num_subl):
                new_checking = checking[:i]+checking[i+1:]
                heapq.heappush(queue, (sum([ p[1] for p in new_checking[:num_subl] ]), new_checking))
print(min(agenda))
0