結果

問題 No.837 Noelちゃんと星々2
ユーザー tcltktcltk
提出日時 2021-01-19 02:20:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 293 ms / 2,000 ms
コード長 1,949 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 107,228 KB
最終ジャッジ日時 2023-09-02 07:33:09
合計ジャッジ時間 10,521 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 290 ms
106,960 KB
testcase_01 AC 291 ms
107,228 KB
testcase_02 AC 290 ms
106,968 KB
testcase_03 AC 289 ms
107,104 KB
testcase_04 AC 289 ms
107,100 KB
testcase_05 AC 293 ms
106,540 KB
testcase_06 AC 288 ms
106,872 KB
testcase_07 AC 290 ms
106,624 KB
testcase_08 AC 288 ms
106,684 KB
testcase_09 AC 231 ms
83,388 KB
testcase_10 AC 233 ms
83,272 KB
testcase_11 AC 233 ms
83,212 KB
testcase_12 AC 231 ms
83,220 KB
testcase_13 AC 232 ms
83,212 KB
testcase_14 AC 235 ms
83,360 KB
testcase_15 AC 232 ms
83,192 KB
testcase_16 AC 229 ms
83,268 KB
testcase_17 AC 236 ms
83,212 KB
testcase_18 AC 230 ms
83,416 KB
testcase_19 AC 231 ms
83,408 KB
testcase_20 AC 228 ms
83,188 KB
testcase_21 AC 232 ms
83,140 KB
testcase_22 AC 234 ms
83,492 KB
testcase_23 AC 232 ms
83,396 KB
testcase_24 AC 227 ms
83,400 KB
testcase_25 AC 230 ms
83,116 KB
testcase_26 AC 226 ms
82,932 KB
testcase_27 AC 227 ms
83,368 KB
testcase_28 AC 228 ms
83,360 KB
testcase_29 AC 230 ms
83,112 KB
testcase_30 AC 230 ms
83,324 KB
testcase_31 AC 232 ms
83,112 KB
testcase_32 AC 231 ms
83,456 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**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