結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,400 KB
testcase_01 AC 42 ms
54,144 KB
testcase_02 AC 42 ms
53,504 KB
testcase_03 AC 41 ms
54,144 KB
testcase_04 AC 46 ms
53,760 KB
testcase_05 AC 118 ms
77,188 KB
testcase_06 AC 106 ms
76,672 KB
testcase_07 AC 125 ms
77,144 KB
testcase_08 AC 106 ms
76,392 KB
testcase_09 AC 102 ms
76,672 KB
testcase_10 AC 98 ms
76,416 KB
testcase_11 AC 112 ms
77,144 KB
testcase_12 AC 102 ms
76,288 KB
testcase_13 AC 117 ms
76,772 KB
testcase_14 AC 99 ms
75,916 KB
testcase_15 AC 356 ms
88,292 KB
testcase_16 AC 365 ms
89,600 KB
testcase_17 AC 344 ms
89,472 KB
testcase_18 AC 333 ms
87,680 KB
testcase_19 AC 325 ms
89,344 KB
testcase_20 AC 357 ms
89,216 KB
testcase_21 AC 365 ms
89,600 KB
testcase_22 AC 359 ms
89,728 KB
testcase_23 AC 359 ms
89,344 KB
testcase_24 AC 340 ms
89,600 KB
testcase_25 AC 99 ms
76,236 KB
testcase_26 AC 101 ms
76,056 KB
testcase_27 AC 100 ms
76,176 KB
testcase_28 AC 104 ms
76,160 KB
testcase_29 AC 102 ms
76,392 KB
testcase_30 AC 110 ms
76,056 KB
testcase_31 AC 114 ms
76,692 KB
testcase_32 AC 96 ms
76,408 KB
testcase_33 AC 103 ms
76,228 KB
testcase_34 AC 107 ms
76,232 KB
testcase_35 AC 106 ms
76,032 KB
testcase_36 AC 103 ms
76,388 KB
testcase_37 AC 107 ms
76,660 KB
testcase_38 AC 110 ms
76,444 KB
testcase_39 AC 108 ms
76,060 KB
testcase_40 AC 112 ms
76,084 KB
testcase_41 AC 107 ms
76,288 KB
testcase_42 AC 106 ms
76,152 KB
testcase_43 AC 107 ms
75,908 KB
testcase_44 AC 103 ms
75,976 KB
testcase_45 AC 394 ms
89,720 KB
testcase_46 AC 358 ms
87,680 KB
testcase_47 AC 382 ms
89,984 KB
testcase_48 AC 355 ms
89,968 KB
testcase_49 AC 370 ms
89,744 KB
testcase_50 AC 383 ms
89,640 KB
testcase_51 AC 378 ms
89,728 KB
testcase_52 AC 372 ms
89,600 KB
testcase_53 AC 367 ms
90,000 KB
testcase_54 AC 374 ms
89,728 KB
testcase_55 AC 383 ms
89,936 KB
testcase_56 AC 375 ms
89,992 KB
testcase_57 AC 372 ms
87,808 KB
testcase_58 AC 368 ms
89,728 KB
testcase_59 AC 399 ms
89,856 KB
testcase_60 AC 389 ms
90,112 KB
testcase_61 AC 370 ms
89,856 KB
testcase_62 AC 351 ms
88,008 KB
testcase_63 AC 372 ms
89,600 KB
testcase_64 AC 388 ms
89,600 KB
testcase_65 AC 202 ms
89,216 KB
testcase_66 AC 178 ms
89,216 KB
testcase_67 AC 267 ms
89,452 KB
testcase_68 AC 273 ms
90,624 KB
testcase_69 WA -
testcase_70 AC 234 ms
91,008 KB
testcase_71 AC 172 ms
89,472 KB
testcase_72 AC 171 ms
89,472 KB
testcase_73 AC 229 ms
90,488 KB
testcase_74 AC 197 ms
90,496 KB
testcase_75 WA -
testcase_76 AC 255 ms
90,752 KB
testcase_77 WA -
testcase_78 WA -
testcase_79 AC 238 ms
90,368 KB
testcase_80 AC 251 ms
90,728 KB
testcase_81 AC 230 ms
90,576 KB
testcase_82 AC 201 ms
90,624 KB
testcase_83 AC 216 ms
90,368 KB
testcase_84 AC 339 ms
89,600 KB
testcase_85 WA -
testcase_86 WA -
testcase_87 AC 360 ms
89,856 KB
testcase_88 AC 344 ms
88,192 KB
testcase_89 AC 42 ms
53,888 KB
testcase_90 AC 42 ms
53,504 KB
testcase_91 AC 41 ms
53,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

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

ans = 1e15
lo, hi = 1, 10**9
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