結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
18,364 KB
testcase_01 AC 54 ms
14,196 KB
testcase_02 AC 44 ms
13,536 KB
testcase_03 AC 51 ms
13,900 KB
testcase_04 AC 39 ms
12,392 KB
testcase_05 AC 89 ms
20,444 KB
testcase_06 AC 78 ms
19,116 KB
testcase_07 AC 56 ms
15,348 KB
testcase_08 AC 32 ms
11,224 KB
testcase_09 AC 45 ms
13,832 KB
testcase_10 AC 63 ms
16,788 KB
testcase_11 AC 65 ms
16,124 KB
testcase_12 AC 75 ms
17,952 KB
testcase_13 AC 35 ms
11,444 KB
testcase_14 AC 31 ms
10,724 KB
testcase_15 AC 83 ms
19,132 KB
testcase_16 AC 91 ms
20,648 KB
testcase_17 AC 78 ms
18,376 KB
testcase_18 AC 44 ms
13,500 KB
testcase_19 AC 78 ms
19,120 KB
testcase_20 AC 93 ms
21,160 KB
testcase_21 AC 91 ms
21,160 KB
testcase_22 AC 92 ms
21,160 KB
testcase_23 AC 91 ms
21,160 KB
testcase_24 AC 92 ms
21,160 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