結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 717 ms
18,304 KB
testcase_01 AC 390 ms
14,140 KB
testcase_02 AC 270 ms
12,952 KB
testcase_03 AC 356 ms
13,844 KB
testcase_04 AC 189 ms
11,808 KB
testcase_05 AC 912 ms
20,384 KB
testcase_06 AC 802 ms
19,060 KB
testcase_07 AC 465 ms
15,292 KB
testcase_08 AC 119 ms
11,168 KB
testcase_09 AC 304 ms
13,244 KB
testcase_10 AC 579 ms
16,632 KB
testcase_11 AC 538 ms
16,068 KB
testcase_12 AC 675 ms
17,896 KB
testcase_13 AC 147 ms
11,388 KB
testcase_14 AC 78 ms
10,668 KB
testcase_15 AC 802 ms
19,076 KB
testcase_16 AC 916 ms
20,596 KB
testcase_17 AC 716 ms
18,320 KB
testcase_18 AC 264 ms
12,652 KB
testcase_19 AC 763 ms
19,064 KB
testcase_20 AC 957 ms
21,104 KB
testcase_21 AC 955 ms
21,104 KB
testcase_22 AC 954 ms
21,104 KB
testcase_23 AC 958 ms
21,104 KB
testcase_24 AC 954 ms
21,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
y = tuple(map(int, input().split()))
m = {}
def f(a):
    if a not in m:
        m[a] = sum(abs(b - a) for b in y)
    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