結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,716 KB
testcase_01 AC 19 ms
8,264 KB
testcase_02 AC 17 ms
8,172 KB
testcase_03 AC 17 ms
8,204 KB
testcase_04 AC 16 ms
8,320 KB
testcase_05 AC 17 ms
8,260 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
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 #

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):
    queue = [sortedl]
    while queue:
        queue.sort(key=lambda l: sum([ p[1] for p in l[:num_subl] ]))
        checking = queue.pop(0)
        if is_valid(num_subl, [ p[0] for p in checking[:num_subl] ]):
            agenda.append(sum([ p[1] for p in checking[:num_subl] ]))
            break
        if len(checking)>num_subl:
            for i in range(num_subl):
                queue.append(checking[:i]+checking[i+1:])
print(min(agenda))
0