結果

問題 No.837 Noelちゃんと星々2
ユーザー tcltktcltk
提出日時 2021-01-19 02:21:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 332 ms / 2,000 ms
コード長 1,925 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 107,780 KB
最終ジャッジ日時 2023-09-02 07:32:49
合計ジャッジ時間 11,789 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 325 ms
107,696 KB
testcase_01 AC 324 ms
107,780 KB
testcase_02 AC 327 ms
107,612 KB
testcase_03 AC 323 ms
107,668 KB
testcase_04 AC 322 ms
107,512 KB
testcase_05 AC 323 ms
107,496 KB
testcase_06 AC 332 ms
107,668 KB
testcase_07 AC 328 ms
107,584 KB
testcase_08 AC 329 ms
107,604 KB
testcase_09 AC 267 ms
83,296 KB
testcase_10 AC 267 ms
83,356 KB
testcase_11 AC 268 ms
83,440 KB
testcase_12 AC 266 ms
83,384 KB
testcase_13 AC 267 ms
83,024 KB
testcase_14 AC 268 ms
83,500 KB
testcase_15 AC 265 ms
83,336 KB
testcase_16 AC 269 ms
83,428 KB
testcase_17 AC 268 ms
83,444 KB
testcase_18 AC 265 ms
83,340 KB
testcase_19 AC 268 ms
83,336 KB
testcase_20 AC 268 ms
83,384 KB
testcase_21 AC 268 ms
83,084 KB
testcase_22 AC 268 ms
83,336 KB
testcase_23 AC 267 ms
83,116 KB
testcase_24 AC 268 ms
83,336 KB
testcase_25 AC 268 ms
83,204 KB
testcase_26 AC 269 ms
83,156 KB
testcase_27 AC 267 ms
83,308 KB
testcase_28 AC 266 ms
83,428 KB
testcase_29 AC 267 ms
83,428 KB
testcase_30 AC 265 ms
83,228 KB
testcase_31 AC 268 ms
83,112 KB
testcase_32 AC 267 ms
83,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
from queue import PriorityQueue
import bisect
import heapq

def input():
    return sys.stdin.readline()[:-1]

sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """85
# -621257465 -621700071 977319124 280693994 413586869 -61854404 -534042095 -754504903 661984431 -642730103 -75092880 394735278 304098754 -462638028 883135080 -41710794 -583480228 -646315301 436933424 -718358057 948871648 116574382 329536301 -892018495 771484877 736879308 510154507 687739912 -812729582 463133064 -131611979 253325107 -357532550 -989477639 -279306846 -569562238 -384581945 -970620976 -614291340 -862786193 -942473729 902523321 278668416 960758681 995172191 409913148 -487787364 -790365768 -199558944 -25846432 211000403 -713532699 834491442 -36591465 358991169 -890258022 -946328742 520894863 419573096 -804935191 544242503 127794285 -670671090 -648557016 409941532 438323505 -714378773 -55763926 -221353249 -175289922 587518468 849584736 720867521 -880338287 -717151732 -886256585 -881253252 336288823 -151364618 -447955247 -327329424 -912220998 793025426 -449536000 21687996
# """
# sys.stdin = io.StringIO(_INPUT)


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

    # 累積和
    S = [0] + list(itertools.accumulate(Y))

    d_min = 10**20
    for k in range(1, N):
        # Y[:k] と Y[k:] に分割
        i1 = k//2
        y1 = Y[i1]
        i2 = k + (N-k)//2
        y2 = Y[i2]
        if y1 == y2:
            d = 1
        else:
            d1 = (y1 * i1 - S[i1]) + (S[k] - S[i1] - y1 * (k - i1))
            d2 = (y2 * (i2 - k) - (S[i2] - S[k])) + (S[N] - S[i2] - y2 * (N - i2))
            d = d1 + d2
        d_min = min(d_min, d)

    print(d_min)

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