結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 693 ms
18,236 KB
testcase_01 AC 376 ms
14,072 KB
testcase_02 AC 263 ms
12,884 KB
testcase_03 AC 347 ms
13,776 KB
testcase_04 AC 182 ms
11,740 KB
testcase_05 AC 876 ms
20,316 KB
testcase_06 AC 777 ms
18,992 KB
testcase_07 AC 451 ms
15,224 KB
testcase_08 AC 116 ms
11,100 KB
testcase_09 AC 297 ms
13,176 KB
testcase_10 AC 557 ms
16,564 KB
testcase_11 AC 526 ms
16,000 KB
testcase_12 AC 654 ms
17,828 KB
testcase_13 AC 142 ms
11,320 KB
testcase_14 AC 76 ms
10,600 KB
testcase_15 AC 785 ms
19,004 KB
testcase_16 AC 887 ms
20,528 KB
testcase_17 AC 701 ms
18,252 KB
testcase_18 AC 259 ms
12,584 KB
testcase_19 AC 745 ms
18,996 KB
testcase_20 AC 927 ms
21,036 KB
testcase_21 AC 924 ms
21,036 KB
testcase_22 AC 935 ms
21,036 KB
testcase_23 AC 936 ms
21,036 KB
testcase_24 AC 929 ms
21,036 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 > 2:
    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
print(min(f(l), f(l + 1), f(l + 2)))
0