結果

問題 No.837 Noelちゃんと星々2
ユーザー kohei2019kohei2019
提出日時 2023-08-12 18:05:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 487 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 82,732 KB
実行使用メモリ 105,292 KB
最終ジャッジ日時 2024-11-20 08:21:31
合計ジャッジ時間 3,848 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
105,056 KB
testcase_01 AC 116 ms
105,292 KB
testcase_02 AC 110 ms
105,080 KB
testcase_03 AC 110 ms
104,960 KB
testcase_04 AC 110 ms
104,832 KB
testcase_05 AC 110 ms
105,220 KB
testcase_06 AC 110 ms
105,184 KB
testcase_07 AC 110 ms
105,088 KB
testcase_08 AC 109 ms
105,088 KB
testcase_09 AC 39 ms
51,712 KB
testcase_10 AC 41 ms
52,096 KB
testcase_11 AC 40 ms
51,712 KB
testcase_12 AC 40 ms
51,968 KB
testcase_13 AC 39 ms
51,968 KB
testcase_14 AC 39 ms
52,096 KB
testcase_15 AC 39 ms
51,840 KB
testcase_16 AC 40 ms
51,840 KB
testcase_17 AC 40 ms
52,096 KB
testcase_18 AC 39 ms
51,968 KB
testcase_19 AC 39 ms
51,968 KB
testcase_20 AC 40 ms
52,480 KB
testcase_21 AC 39 ms
51,840 KB
testcase_22 AC 38 ms
52,352 KB
testcase_23 AC 40 ms
51,968 KB
testcase_24 AC 39 ms
52,368 KB
testcase_25 AC 39 ms
51,712 KB
testcase_26 AC 40 ms
52,096 KB
testcase_27 AC 40 ms
51,968 KB
testcase_28 AC 39 ms
51,968 KB
testcase_29 AC 39 ms
51,584 KB
testcase_30 AC 40 ms
51,712 KB
testcase_31 AC 40 ms
51,584 KB
testcase_32 AC 40 ms
51,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
lsY = list(map(int,input().split()))
lsY.sort()

m1 = lsY[0]
m2 = lsY[(N//2)]

v1 = 0
v2 = sum([abs(lsY[i]-m2) for i in range(1,N)])
ans = v1+v2

for i in range(N-2):
    m1n = lsY[(i+1)//2]
    m2n = lsY[(N+i+1)//2]
    v1 += (m1n-m1)*((i+1)//2)-(m1n-m1)*(i+1-(i+1)//2)+(lsY[i+1]-m1n)
    v2 += (m2n-m2)*(N//2-1-(i+1)//2)-(m2n-m2)*(N//2-(i+1)//2)-(m2-lsY[i+1])
    m1 = m1n
    m2 = m2n
    ans = min(ans,v1+v2)

if len(set(lsY)) == 1:
    print(1)
else:
    print(ans)
0