結果

問題 No.615 集合に分けよう
ユーザー buey_tbuey_t
提出日時 2023-03-31 09:55:37
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,181 bytes
コンパイル時間 773 ms
コンパイル使用メモリ 81,728 KB
実行使用メモリ 146,824 KB
最終ジャッジ日時 2023-10-23 22:00:50
合計ジャッジ時間 12,153 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
88,544 KB
testcase_01 AC 138 ms
88,548 KB
testcase_02 AC 139 ms
88,544 KB
testcase_03 AC 140 ms
88,544 KB
testcase_04 AC 146 ms
89,024 KB
testcase_05 AC 147 ms
89,032 KB
testcase_06 WA -
testcase_07 AC 150 ms
88,724 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 150 ms
88,760 KB
testcase_11 AC 150 ms
88,764 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 185 ms
89,236 KB
testcase_16 AC 1,113 ms
95,192 KB
testcase_17 AC 423 ms
146,824 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 999 ms
95,072 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 125 ms
84,004 KB
testcase_26 AC 126 ms
84,004 KB
testcase_27 AC 387 ms
145,388 KB
testcase_28 AC 383 ms
145,392 KB
testcase_29 AC 406 ms
146,324 KB
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
    from heapq import heapify, heappop, heappush
    from bisect import bisect_left, bisect_right
    from copy import deepcopy
    import copy
    import random
    from collections import deque,Counter,defaultdict
    from itertools import permutations,combinations
    from decimal import Decimal,ROUND_HALF_UP
    #tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
    from functools import lru_cache, reduce
    #@lru_cache(maxsize=None)
    from operator import add,sub,mul,xor,and_,or_,itemgetter
    INF = 10**18
    mod1 = 10**9+7
    mod2 = 998244353
    
    #DecimalならPython
    #再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!!
    
    
    '''
    
    
    
    '''
    
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    
    A.sort()
    h = INF
    l = -1
    
    while h-l > 1:
        
        m = (h+l)//2
        
        mx = -INF
        mi = INF
        cnt = 0
        for i in range(N):
            mx = max(A[i],mx)
            mi = min(A[i],mi)
            
            if mx-mi > m:
                
                cnt += 1
                mx = A[i]
                mi = A[i]
        cnt += 1
        
        if cnt > K:
            l = m
        else:
            h = m
    
    ans = INF
    for k in range(l,l+200):
        if k < 0:
            continue
        
        mx = -INF
        mi = INF
        cnt = 0
        tmp = 0
        ls = []
        for i in range(N):
            mx = max(A[i],mx)
            mi = min(A[i],mi)
            
            if mx-mi > k:
                cnt += 1
                tmp += max(ls)-min(ls)
                mx = A[i]
                mi = A[i]
                ls = []
            ls.append(A[i])
        
        tmp += max(ls)-min(ls)
        cnt += 1
        
        if cnt == K:
            ans = min(ans,tmp)
    
    print(ans)
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if __name__ == '__main__':
    main()
0