結果

問題 No.609 Noelちゃんと星々
ユーザー daku9640daku9640
提出日時 2018-08-11 23:01:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 294 ms / 2,000 ms
コード長 535 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 11,796 KB
実行使用メモリ 21,088 KB
最終ジャッジ日時 2023-10-24 14:15:38
合計ジャッジ時間 6,110 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 221 ms
18,288 KB
testcase_01 AC 116 ms
14,120 KB
testcase_02 AC 83 ms
12,672 KB
testcase_03 AC 109 ms
13,828 KB
testcase_04 AC 63 ms
11,788 KB
testcase_05 AC 269 ms
20,372 KB
testcase_06 AC 238 ms
19,044 KB
testcase_07 AC 140 ms
15,276 KB
testcase_08 AC 49 ms
11,148 KB
testcase_09 AC 92 ms
13,232 KB
testcase_10 AC 175 ms
16,716 KB
testcase_11 AC 164 ms
16,052 KB
testcase_12 AC 201 ms
17,876 KB
testcase_13 AC 54 ms
11,360 KB
testcase_14 AC 41 ms
10,648 KB
testcase_15 AC 237 ms
19,060 KB
testcase_16 AC 281 ms
20,576 KB
testcase_17 AC 221 ms
18,304 KB
testcase_18 AC 83 ms
12,632 KB
testcase_19 AC 228 ms
19,044 KB
testcase_20 AC 279 ms
21,088 KB
testcase_21 AC 293 ms
21,088 KB
testcase_22 AC 294 ms
21,088 KB
testcase_23 AC 284 ms
21,088 KB
testcase_24 AC 288 ms
21,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect, insort_left, insort
n = int(input())
y = sorted(map(int, input().split()))
len_y = len(y)
m = {}
def f(a):
    if a not in m:
        l = bisect_left(y, a)
        m[a] = abs(sum(y[:l]) - a * l) + abs(sum(y[l:]) - a * (len_y - l))
    return m[a]
l = min(y)
r = max(y)
for _ in range(100):
    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
ans = 1e15
for i in range(l, r + 1):
    ans = min(ans, f(i))
print(ans)
0