結果

問題 No.738 平らな農地
ユーザー roiti46roiti46
提出日時 2018-09-28 22:11:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 682 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 91,584 KB
最終ジャッジ日時 2024-04-20 10:47:45
合計ジャッジ時間 22,602 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,340 KB
testcase_01 AC 44 ms
55,520 KB
testcase_02 AC 43 ms
53,992 KB
testcase_03 AC 42 ms
54,772 KB
testcase_04 AC 41 ms
54,836 KB
testcase_05 AC 117 ms
77,652 KB
testcase_06 AC 107 ms
76,508 KB
testcase_07 AC 120 ms
77,352 KB
testcase_08 AC 107 ms
76,500 KB
testcase_09 AC 101 ms
76,668 KB
testcase_10 AC 98 ms
76,496 KB
testcase_11 AC 115 ms
77,084 KB
testcase_12 AC 103 ms
76,280 KB
testcase_13 AC 116 ms
77,544 KB
testcase_14 AC 99 ms
76,396 KB
testcase_15 AC 360 ms
88,272 KB
testcase_16 AC 364 ms
89,528 KB
testcase_17 AC 344 ms
89,552 KB
testcase_18 AC 336 ms
88,652 KB
testcase_19 AC 339 ms
89,812 KB
testcase_20 AC 361 ms
90,032 KB
testcase_21 AC 360 ms
90,476 KB
testcase_22 AC 347 ms
89,768 KB
testcase_23 AC 347 ms
89,904 KB
testcase_24 AC 335 ms
89,840 KB
testcase_25 AC 99 ms
76,556 KB
testcase_26 AC 98 ms
76,140 KB
testcase_27 AC 100 ms
76,464 KB
testcase_28 AC 105 ms
76,104 KB
testcase_29 AC 105 ms
76,600 KB
testcase_30 AC 112 ms
76,724 KB
testcase_31 AC 114 ms
76,960 KB
testcase_32 AC 99 ms
76,728 KB
testcase_33 AC 104 ms
76,792 KB
testcase_34 AC 106 ms
76,384 KB
testcase_35 AC 102 ms
76,264 KB
testcase_36 AC 104 ms
76,720 KB
testcase_37 AC 108 ms
76,240 KB
testcase_38 AC 109 ms
76,236 KB
testcase_39 AC 109 ms
76,312 KB
testcase_40 AC 114 ms
77,280 KB
testcase_41 AC 107 ms
76,232 KB
testcase_42 AC 104 ms
76,640 KB
testcase_43 AC 105 ms
76,332 KB
testcase_44 AC 99 ms
76,208 KB
testcase_45 AC 391 ms
89,912 KB
testcase_46 AC 364 ms
88,560 KB
testcase_47 AC 378 ms
89,844 KB
testcase_48 AC 355 ms
89,848 KB
testcase_49 AC 368 ms
89,668 KB
testcase_50 AC 381 ms
89,776 KB
testcase_51 AC 367 ms
89,868 KB
testcase_52 AC 368 ms
89,836 KB
testcase_53 AC 369 ms
90,228 KB
testcase_54 AC 375 ms
89,816 KB
testcase_55 AC 388 ms
90,208 KB
testcase_56 AC 375 ms
89,788 KB
testcase_57 AC 369 ms
88,528 KB
testcase_58 AC 371 ms
89,980 KB
testcase_59 AC 399 ms
89,936 KB
testcase_60 AC 408 ms
90,236 KB
testcase_61 AC 369 ms
90,228 KB
testcase_62 AC 350 ms
88,164 KB
testcase_63 AC 375 ms
90,036 KB
testcase_64 AC 384 ms
89,960 KB
testcase_65 AC 224 ms
89,696 KB
testcase_66 AC 167 ms
89,796 KB
testcase_67 AC 259 ms
89,212 KB
testcase_68 WA -
testcase_69 WA -
testcase_70 AC 241 ms
91,244 KB
testcase_71 AC 70 ms
83,056 KB
testcase_72 AC 73 ms
86,920 KB
testcase_73 AC 74 ms
88,940 KB
testcase_74 AC 75 ms
88,704 KB
testcase_75 WA -
testcase_76 AC 264 ms
90,860 KB
testcase_77 WA -
testcase_78 WA -
testcase_79 AC 235 ms
91,004 KB
testcase_80 AC 249 ms
91,416 KB
testcase_81 AC 223 ms
90,820 KB
testcase_82 AC 201 ms
90,928 KB
testcase_83 AC 214 ms
90,508 KB
testcase_84 AC 341 ms
90,216 KB
testcase_85 WA -
testcase_86 WA -
testcase_87 AC 360 ms
90,336 KB
testcase_88 AC 349 ms
88,740 KB
testcase_89 AC 41 ms
54,192 KB
testcase_90 AC 40 ms
54,616 KB
testcase_91 AC 40 ms
54,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

N, K = map(int, input().split())
A = list(map(int, input().split()))

ans = 1e17
lo, hi = min(A), max(A)
while lo <= hi:
    l = (2*lo + hi)//3
    h = (lo + 2*hi)//3
    s_l = min_l = sum(abs(A[j] - l) for j in range(K))
    for j in range(K, N):
        s_l = s_l - abs(A[j - K] - l) + abs(A[j] - l)
        min_l = min(min_l, s_l)
    s_h = min_h = sum(abs(A[j] - h) for j in range(K))
    for j in range(K, N):
        s_h = s_h - abs(A[j - K] - h) + abs(A[j] - h)
        min_h = min(min_h, s_h)

    if min_l < min_h:
        hi = h - 1
        ans = min(ans, min_l)
    else:
        lo = l + 1
        ans = min(ans, min_h)
print(ans) 

0