結果

問題 No.837 Noelちゃんと星々2
ユーザー nomemseanomemsea
提出日時 2019-06-14 22:37:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 1,514 ms
コンパイル使用メモリ 86,304 KB
実行使用メモリ 98,476 KB
最終ジャッジ日時 2023-09-02 07:21:31
合計ジャッジ時間 6,480 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 192 ms
98,184 KB
testcase_01 AC 190 ms
98,160 KB
testcase_02 AC 188 ms
98,420 KB
testcase_03 AC 188 ms
97,996 KB
testcase_04 AC 188 ms
98,304 KB
testcase_05 AC 191 ms
98,140 KB
testcase_06 AC 198 ms
98,124 KB
testcase_07 AC 197 ms
98,420 KB
testcase_08 AC 198 ms
98,476 KB
testcase_09 AC 127 ms
76,224 KB
testcase_10 AC 119 ms
76,652 KB
testcase_11 AC 119 ms
76,272 KB
testcase_12 AC 118 ms
76,444 KB
testcase_13 AC 118 ms
76,712 KB
testcase_14 AC 118 ms
76,504 KB
testcase_15 AC 119 ms
76,536 KB
testcase_16 AC 124 ms
76,292 KB
testcase_17 AC 118 ms
76,556 KB
testcase_18 AC 117 ms
76,344 KB
testcase_19 AC 116 ms
76,332 KB
testcase_20 AC 118 ms
76,588 KB
testcase_21 AC 116 ms
76,456 KB
testcase_22 AC 117 ms
76,292 KB
testcase_23 AC 117 ms
76,588 KB
testcase_24 AC 118 ms
76,392 KB
testcase_25 AC 119 ms
76,444 KB
testcase_26 AC 120 ms
76,588 KB
testcase_27 AC 119 ms
76,676 KB
testcase_28 AC 119 ms
76,436 KB
testcase_29 AC 119 ms
76,328 KB
testcase_30 AC 125 ms
76,348 KB
testcase_31 AC 119 ms
76,344 KB
testcase_32 AC 119 ms
76,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

N = int(input())
Y = list(map(int,input().split()))
Y.sort()
S  =[0]*(N+1)
def mid(x,y,l):
    a = y-x
    if a%2 == 0:
        return a//2,l[a//2+x]
    else:
        return (a-1)//2+1,(l[(a-1)//2+x]+l[(a-1)//2+1+x])//2
ans = inf
for i in range(1,N+1):
    S[i] += S[i-1]+Y[i-1]
for i in range(1,N):
    x1,m1 = mid(0,i-1,Y)
    x2,m2 = mid(i,N-1,Y)
    if m1 == m2:
        m2 = m1+1
    cur = (m1*x1-S[x1])+(S[i]-S[x1]-m1*(i-x1))
    cur += abs((m2*x2-(S[i+x2]-S[i])))+abs((S[N]-S[i+x2]-m2*(N-i-x2)))
    ans = min(ans,cur)
print(ans)
0