結果

問題 No.837 Noelちゃんと星々2
ユーザー tcltktcltk
提出日時 2021-01-19 02:20:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,949 bytes
コンパイル時間 805 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 112,000 KB
最終ジャッジ日時 2024-05-08 19:53:15
合計ジャッジ時間 7,878 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 AC 142 ms
88,960 KB
testcase_10 AC 144 ms
89,088 KB
testcase_11 AC 147 ms
88,832 KB
testcase_12 AC 145 ms
88,960 KB
testcase_13 AC 143 ms
89,088 KB
testcase_14 AC 144 ms
89,088 KB
testcase_15 AC 138 ms
88,960 KB
testcase_16 AC 144 ms
88,960 KB
testcase_17 AC 144 ms
89,216 KB
testcase_18 AC 143 ms
89,216 KB
testcase_19 AC 140 ms
89,216 KB
testcase_20 AC 143 ms
88,832 KB
testcase_21 AC 141 ms
88,832 KB
testcase_22 AC 143 ms
89,088 KB
testcase_23 AC 148 ms
89,216 KB
testcase_24 AC 141 ms
88,704 KB
testcase_25 AC 141 ms
89,088 KB
testcase_26 AC 151 ms
89,216 KB
testcase_27 AC 140 ms
89,088 KB
testcase_28 AC 144 ms
88,960 KB
testcase_29 AC 141 ms
89,088 KB
testcase_30 AC 142 ms
89,088 KB
testcase_31 AC 139 ms
88,704 KB
testcase_32 AC 142 ms
89,088 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]
    for i in range(N):
        S.append(S[-1] + Y[i])

    d_min = 10**12
    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