結果

問題 No.609 Noelちゃんと星々
ユーザー GrayCoderGrayCoder
提出日時 2017-12-09 20:55:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 347 bytes
コンパイル時間 115 ms
コンパイル使用メモリ 10,572 KB
実行使用メモリ 25,636 KB
最終ジャッジ日時 2023-08-20 05:19:41
合計ジャッジ時間 3,509 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
19,828 KB
testcase_01 AC 57 ms
14,852 KB
testcase_02 AC 46 ms
13,268 KB
testcase_03 AC 55 ms
14,488 KB
testcase_04 AC 36 ms
11,344 KB
testcase_05 AC 128 ms
24,788 KB
testcase_06 AC 107 ms
20,548 KB
testcase_07 AC 71 ms
16,732 KB
testcase_08 AC 29 ms
10,112 KB
testcase_09 AC 50 ms
13,988 KB
testcase_10 AC 82 ms
18,300 KB
testcase_11 AC 76 ms
17,644 KB
testcase_12 AC 93 ms
19,256 KB
testcase_13 AC 32 ms
10,920 KB
testcase_14 AC 23 ms
9,140 KB
testcase_15 AC 110 ms
20,540 KB
testcase_16 AC 126 ms
24,764 KB
testcase_17 AC 101 ms
19,840 KB
testcase_18 AC 45 ms
13,232 KB
testcase_19 AC 105 ms
20,536 KB
testcase_20 AC 139 ms
25,632 KB
testcase_21 AC 134 ms
25,636 KB
testcase_22 AC 133 ms
25,624 KB
testcase_23 AC 133 ms
25,516 KB
testcase_24 AC 136 ms
25,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter

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

    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