結果

問題 No.609 Noelちゃんと星々
ユーザー daku9640daku9640
提出日時 2018-08-12 01:13:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 81,640 KB
実行使用メモリ 94,656 KB
最終ジャッジ日時 2023-10-24 14:18:05
合計ジャッジ時間 4,087 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
86,952 KB
testcase_01 AC 61 ms
72,412 KB
testcase_02 AC 56 ms
69,288 KB
testcase_03 AC 60 ms
71,372 KB
testcase_04 AC 53 ms
66,804 KB
testcase_05 AC 91 ms
94,520 KB
testcase_06 AC 83 ms
87,368 KB
testcase_07 AC 68 ms
77,116 KB
testcase_08 AC 48 ms
63,844 KB
testcase_09 AC 58 ms
70,184 KB
testcase_10 AC 73 ms
80,448 KB
testcase_11 AC 70 ms
78,780 KB
testcase_12 AC 78 ms
84,796 KB
testcase_13 AC 49 ms
63,844 KB
testcase_14 AC 46 ms
61,796 KB
testcase_15 AC 85 ms
89,388 KB
testcase_16 AC 94 ms
94,504 KB
testcase_17 AC 82 ms
86,956 KB
testcase_18 AC 56 ms
69,268 KB
testcase_19 AC 83 ms
87,368 KB
testcase_20 AC 92 ms
94,648 KB
testcase_21 AC 93 ms
94,656 KB
testcase_22 AC 93 ms
94,656 KB
testcase_23 AC 92 ms
94,648 KB
testcase_24 AC 93 ms
94,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect, insort_left, insort
from itertools import accumulate
n = int(input())
y = sorted(map(int, input().split()))
sum_y = tuple(accumulate(y))
m = {}
def f(a):
    if a not in m:
        l = bisect_left(y, a)
        m[a] = abs(sum_y[l - 1] - a * l) + abs((sum_y[-1] - sum_y[l - 1]) - a * (n - l))
    return m[a]
l = y[0]
r = y[-1]
while r - l > 2:
    mid_l = (l * 2 + r) // 3
    mid_r = (l + r * 2) // 3
    if f(mid_l) > f(mid_r):
        l = mid_l
    else:
        r = mid_r
print(min(f(l), f(l + 1), f(l + 2)))
0