結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
18,360 KB
testcase_01 AC 86 ms
14,192 KB
testcase_02 AC 71 ms
12,744 KB
testcase_03 AC 79 ms
13,900 KB
testcase_04 AC 53 ms
11,860 KB
testcase_05 AC 180 ms
20,444 KB
testcase_06 AC 155 ms
19,116 KB
testcase_07 AC 99 ms
15,348 KB
testcase_08 AC 43 ms
11,220 KB
testcase_09 AC 70 ms
13,304 KB
testcase_10 AC 123 ms
16,788 KB
testcase_11 AC 116 ms
16,124 KB
testcase_12 AC 135 ms
17,948 KB
testcase_13 AC 46 ms
11,428 KB
testcase_14 AC 36 ms
10,716 KB
testcase_15 AC 156 ms
19,132 KB
testcase_16 AC 181 ms
20,648 KB
testcase_17 AC 145 ms
18,376 KB
testcase_18 AC 65 ms
12,704 KB
testcase_19 AC 156 ms
19,116 KB
testcase_20 AC 192 ms
21,160 KB
testcase_21 AC 190 ms
21,160 KB
testcase_22 AC 190 ms
21,160 KB
testcase_23 AC 194 ms
21,160 KB
testcase_24 AC 187 ms
21,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect, insort_left, insort
n = int(input())
y = sorted(map(int, input().split()))
sum_y = sum(y)
m = {}
def f(a):
    if a not in m:
        l = bisect_left(y, a)
        sum_yl = sum(y[:l])
        m[a] = abs(sum_yl - a * l) + abs((sum_y - sum_yl) - a * (n - 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