結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 702 ms
18,368 KB
testcase_01 AC 391 ms
14,204 KB
testcase_02 AC 273 ms
13,016 KB
testcase_03 AC 352 ms
13,908 KB
testcase_04 AC 189 ms
11,872 KB
testcase_05 AC 908 ms
20,448 KB
testcase_06 AC 800 ms
19,128 KB
testcase_07 AC 459 ms
15,356 KB
testcase_08 AC 117 ms
11,232 KB
testcase_09 AC 304 ms
13,308 KB
testcase_10 AC 578 ms
16,796 KB
testcase_11 AC 540 ms
16,132 KB
testcase_12 AC 662 ms
17,960 KB
testcase_13 AC 146 ms
11,444 KB
testcase_14 AC 77 ms
10,732 KB
testcase_15 AC 790 ms
19,140 KB
testcase_16 AC 907 ms
20,660 KB
testcase_17 AC 714 ms
18,384 KB
testcase_18 AC 261 ms
12,716 KB
testcase_19 AC 774 ms
19,128 KB
testcase_20 AC 977 ms
21,168 KB
testcase_21 AC 974 ms
21,168 KB
testcase_22 AC 968 ms
21,168 KB
testcase_23 AC 966 ms
21,168 KB
testcase_24 AC 968 ms
21,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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