結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 968 ms
18,240 KB
testcase_01 AC 518 ms
14,076 KB
testcase_02 AC 362 ms
13,680 KB
testcase_03 AC 472 ms
14,836 KB
testcase_04 AC 250 ms
12,536 KB
testcase_05 AC 1,284 ms
20,580 KB
testcase_06 AC 1,099 ms
19,000 KB
testcase_07 AC 624 ms
15,228 KB
testcase_08 AC 147 ms
11,104 KB
testcase_09 AC 400 ms
14,500 KB
testcase_10 AC 789 ms
16,736 KB
testcase_11 AC 734 ms
16,488 KB
testcase_12 AC 906 ms
17,832 KB
testcase_13 AC 187 ms
11,316 KB
testcase_14 AC 93 ms
10,604 KB
testcase_15 AC 1,105 ms
19,084 KB
testcase_16 AC 1,277 ms
20,592 KB
testcase_17 AC 998 ms
18,256 KB
testcase_18 AC 350 ms
13,644 KB
testcase_19 AC 1,071 ms
19,000 KB
testcase_20 AC 1,351 ms
21,040 KB
testcase_21 AC 1,363 ms
21,040 KB
testcase_22 AC 1,352 ms
21,040 KB
testcase_23 AC 1,351 ms
21,040 KB
testcase_24 AC 1,351 ms
21,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
n = int(input())
y = tuple(map(int, input().split()))
m = {}
def f(a):
    if a not in m:
        m[a] = tuple(itertools.accumulate(abs(b - a) for b in y))[-1]
    return m[a]
l = min(y)
r = max(y)
while r - l > 10:
    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