結果

問題 No.837 Noelちゃんと星々2
ユーザー tails1434tails1434
提出日時 2020-01-06 22:03:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 705 bytes
コンパイル時間 1,210 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 140,544 KB
最終ジャッジ日時 2024-05-02 10:56:56
合計ジャッジ時間 9,026 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 171 ms
88,192 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 142 ms
88,320 KB
testcase_25 AC 139 ms
88,192 KB
testcase_26 AC 145 ms
88,448 KB
testcase_27 AC 138 ms
88,192 KB
testcase_28 AC 138 ms
88,448 KB
testcase_29 AC 140 ms
88,448 KB
testcase_30 AC 141 ms
88,320 KB
testcase_31 AC 140 ms
88,192 KB
testcase_32 AC 141 ms
88,576 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import statistics
from itertools import accumulate

def main():
    N = int(input())
    Y = list(map(int, input().split()))
    sort_Y = sorted(Y)
    if len(set(Y)) == 1:
        print(1)
        exit()
    elif len(set(Y)) == 2:
        print(0)
        exit()

    A = list(accumulate(sort_Y))
    m = Y[N // 2]
    ans = float('inf')
    first_half = 0
    second_half = 0
    for y in sort_Y:
        second_half += abs(m - y)
    for i in range(N-1):
        m1 = sort_Y[i // 2]
        m2 = sort_Y[(i + N) // 2]

        first_half += sort_Y[i] - m1
        second_half -= m2 - sort_Y[i]

        ans = min(ans, first_half + second_half)

    print(ans)
    

if __name__ == "__main__":
    main()
0