結果

問題 No.609 Noelちゃんと星々
ユーザー GrayCoderGrayCoder
提出日時 2017-12-09 20:52:56
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 421 bytes
コンパイル時間 378 ms
コンパイル使用メモリ 10,600 KB
実行使用メモリ 25,712 KB
最終ジャッジ日時 2023-08-20 05:19:14
合計ジャッジ時間 3,663 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
19,824 KB
testcase_01 AC 57 ms
14,748 KB
testcase_02 AC 46 ms
13,220 KB
testcase_03 AC 54 ms
14,556 KB
testcase_04 AC 36 ms
11,444 KB
testcase_05 AC 132 ms
24,496 KB
testcase_06 AC 105 ms
20,604 KB
testcase_07 AC 70 ms
16,808 KB
testcase_08 AC 28 ms
10,216 KB
testcase_09 AC 49 ms
14,232 KB
testcase_10 AC 82 ms
18,088 KB
testcase_11 AC 76 ms
17,520 KB
testcase_12 AC 92 ms
19,428 KB
testcase_13 AC 32 ms
10,856 KB
testcase_14 AC 24 ms
9,300 KB
testcase_15 AC 105 ms
20,708 KB
testcase_16 AC 128 ms
24,860 KB
testcase_17 AC 99 ms
19,800 KB
testcase_18 AC 44 ms
13,300 KB
testcase_19 AC 107 ms
20,668 KB
testcase_20 AC 135 ms
25,608 KB
testcase_21 AC 127 ms
25,712 KB
testcase_22 AC 127 ms
25,592 KB
testcase_23 AC 128 ms
25,632 KB
testcase_24 AC 129 ms
25,588 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