結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 150 ms
18,296 KB
testcase_01 AC 87 ms
14,128 KB
testcase_02 AC 66 ms
12,676 KB
testcase_03 AC 80 ms
13,832 KB
testcase_04 AC 54 ms
11,796 KB
testcase_05 AC 187 ms
20,376 KB
testcase_06 AC 159 ms
19,048 KB
testcase_07 AC 100 ms
15,280 KB
testcase_08 AC 44 ms
11,156 KB
testcase_09 AC 72 ms
13,236 KB
testcase_10 AC 120 ms
16,720 KB
testcase_11 AC 118 ms
16,056 KB
testcase_12 AC 139 ms
17,884 KB
testcase_13 AC 48 ms
11,364 KB
testcase_14 AC 37 ms
10,652 KB
testcase_15 AC 162 ms
19,064 KB
testcase_16 AC 188 ms
20,580 KB
testcase_17 AC 151 ms
18,308 KB
testcase_18 AC 67 ms
12,640 KB
testcase_19 AC 159 ms
19,052 KB
testcase_20 AC 189 ms
21,092 KB
testcase_21 AC 186 ms
21,092 KB
testcase_22 AC 189 ms
21,092 KB
testcase_23 AC 191 ms
21,092 KB
testcase_24 AC 190 ms
21,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect, insort_left, insort
n = int(input())
y = sorted(map(int, input().split()))
sum_y = sum(y)
len_y = len(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 * (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