結果

問題 No.609 Noelちゃんと星々
ユーザー tails1434tails1434
提出日時 2020-02-12 07:29:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 759 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 82,608 KB
実行使用メモリ 86,892 KB
最終ジャッジ日時 2024-04-10 08:09:41
合計ジャッジ時間 4,200 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 141 ms
86,892 KB
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 AC 125 ms
83,656 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 72 ms
68,632 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 132 ms
85,884 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    N = int(input())
    Y = list(map(int, input().split()))
    def check(mid_left, mid_right):
        sum1 = 0
        sum2 = 0
        for i in range(N):
            sum1 += abs(mid_left-Y[i])
            sum2 += abs(mid_right-Y[i])
        if sum1 >= sum2:
            return True
        else:
            return False

    r = Y[-1]
    l = Y[0]
    while abs(r - l) > 2:
        mid_l = (l * 2 + r) // 3
        mid_r = (l + r * 2) // 3
        if check(mid_l, mid_r):
            l = mid_l
        else:
            r = mid_r 

    ans = float('inf')
    for a in range(l,r+1):
        tmp = 0
        for i in range(N):
            tmp += abs(a - Y[i])
        ans = min(ans, tmp)
    print(ans)




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