結果

問題 No.837 Noelちゃんと星々2
ユーザー maspymaspy
提出日時 2020-02-02 13:22:06
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 208 ms / 2,000 ms
コード長 789 bytes
コンパイル時間 137 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 29,056 KB
最終ジャッジ日時 2023-09-02 07:29:58
合計ジャッジ時間 4,138 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 197 ms
29,028 KB
testcase_01 AC 199 ms
29,004 KB
testcase_02 AC 194 ms
29,028 KB
testcase_03 AC 208 ms
28,968 KB
testcase_04 AC 199 ms
29,008 KB
testcase_05 AC 201 ms
28,984 KB
testcase_06 AC 197 ms
28,912 KB
testcase_07 AC 198 ms
28,956 KB
testcase_08 AC 204 ms
29,056 KB
testcase_09 AC 18 ms
8,580 KB
testcase_10 AC 18 ms
8,648 KB
testcase_11 AC 19 ms
8,540 KB
testcase_12 AC 18 ms
8,620 KB
testcase_13 AC 18 ms
8,584 KB
testcase_14 AC 19 ms
8,532 KB
testcase_15 AC 19 ms
8,664 KB
testcase_16 AC 18 ms
8,632 KB
testcase_17 AC 19 ms
8,668 KB
testcase_18 AC 19 ms
8,580 KB
testcase_19 AC 18 ms
8,508 KB
testcase_20 AC 18 ms
8,648 KB
testcase_21 AC 18 ms
8,592 KB
testcase_22 AC 18 ms
8,580 KB
testcase_23 AC 19 ms
8,512 KB
testcase_24 AC 18 ms
8,528 KB
testcase_25 AC 19 ms
8,684 KB
testcase_26 AC 18 ms
8,656 KB
testcase_27 AC 19 ms
8,624 KB
testcase_28 AC 18 ms
8,644 KB
testcase_29 AC 19 ms
8,504 KB
testcase_30 AC 19 ms
8,528 KB
testcase_31 AC 18 ms
8,548 KB
testcase_32 AC 18 ms
8,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

N,*Y = map(int,read().split())

Y.sort()

if Y[0] == Y[-1]:
    print(1)
    exit()

def calc_left_sum(Y):
    n_left = 0
    right = deque()
    s_l = 0
    s_r = 0
    ret = [10 ** 18]
    for y in Y:
        right.append(y)
        s_r += y
        if n_left + 1 < len(right):
            n_left += 1
            x = right.popleft()
            s_l += x
            s_r -= x
        mid = right[0]
        D = (mid * n_left - s_l)
        D += (s_r - mid * len(right))
        ret.append(D)
    return ret

L = calc_left_sum(Y)
R = calc_left_sum([-y for y in Y[::-1]])

answer = min(x+y for x,y in zip(L[1:N], R[1:N][::-1]))
print(answer)
0