結果

問題 No.609 Noelちゃんと星々
ユーザー GrayCoderGrayCoder
提出日時 2017-12-09 20:52:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 421 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 27,888 KB
最終ジャッジ日時 2024-05-07 12:40:54
合計ジャッジ時間 4,274 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
22,156 KB
testcase_01 AC 79 ms
16,652 KB
testcase_02 AC 63 ms
15,960 KB
testcase_03 AC 72 ms
17,200 KB
testcase_04 AC 51 ms
13,916 KB
testcase_05 AC 167 ms
26,728 KB
testcase_06 AC 140 ms
23,024 KB
testcase_07 AC 94 ms
19,132 KB
testcase_08 AC 45 ms
12,160 KB
testcase_09 AC 67 ms
16,240 KB
testcase_10 AC 108 ms
20,508 KB
testcase_11 AC 109 ms
19,732 KB
testcase_12 AC 127 ms
21,668 KB
testcase_13 AC 46 ms
13,056 KB
testcase_14 AC 39 ms
11,392 KB
testcase_15 AC 142 ms
23,188 KB
testcase_16 AC 170 ms
27,184 KB
testcase_17 AC 129 ms
22,180 KB
testcase_18 AC 61 ms
16,036 KB
testcase_19 AC 137 ms
23,028 KB
testcase_20 AC 173 ms
27,804 KB
testcase_21 AC 167 ms
27,864 KB
testcase_22 AC 169 ms
27,796 KB
testcase_23 AC 164 ms
27,864 KB
testcase_24 AC 171 ms
27,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter
from bisect import bisect

def main():
    N = int(input())
    Y = tuple(map(int, input().split()))

    if N == 1:
        print(0)
        return

    c = Counter(Y).most_common()
    y = sorted(Y)
    idx = N // 2
    dist = float('inf')
    for i in (c[0][0], y[idx]):
        n = 0
        for j in y:
            n += abs(i - j)
        dist = min(dist, n)

    print(dist)

main()
0