結果

問題 No.609 Noelちゃんと星々
ユーザー daku9640daku9640
提出日時 2018-08-12 01:09:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 556 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 11,872 KB
実行使用メモリ 21,080 KB
最終ジャッジ日時 2023-10-24 14:17:48
合計ジャッジ時間 4,278 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
18,284 KB
testcase_01 AC 58 ms
14,116 KB
testcase_02 AC 51 ms
13,456 KB
testcase_03 AC 61 ms
13,820 KB
testcase_04 AC 44 ms
12,312 KB
testcase_05 AC 107 ms
20,364 KB
testcase_06 AC 98 ms
19,036 KB
testcase_07 AC 66 ms
15,268 KB
testcase_08 AC 38 ms
11,144 KB
testcase_09 AC 53 ms
13,752 KB
testcase_10 AC 75 ms
16,708 KB
testcase_11 AC 69 ms
16,044 KB
testcase_12 AC 86 ms
17,872 KB
testcase_13 AC 41 ms
11,360 KB
testcase_14 AC 35 ms
10,644 KB
testcase_15 AC 99 ms
19,052 KB
testcase_16 AC 126 ms
20,568 KB
testcase_17 AC 92 ms
18,296 KB
testcase_18 AC 49 ms
13,420 KB
testcase_19 AC 90 ms
19,040 KB
testcase_20 AC 105 ms
21,080 KB
testcase_21 AC 108 ms
21,080 KB
testcase_22 AC 108 ms
21,080 KB
testcase_23 AC 99 ms
21,080 KB
testcase_24 AC 96 ms
21,080 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 = min(y)
r = max(y)
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