結果

問題 No.837 Noelちゃんと星々2
ユーザー hedwig100hedwig100
提出日時 2020-04-18 22:18:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 1,008 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 21,372 KB
最終ジャッジ日時 2023-09-02 07:30:45
合計ジャッジ時間 3,335 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 153 ms
21,372 KB
testcase_01 AC 149 ms
21,288 KB
testcase_02 AC 147 ms
21,136 KB
testcase_03 AC 153 ms
21,168 KB
testcase_04 AC 151 ms
21,284 KB
testcase_05 AC 146 ms
21,248 KB
testcase_06 AC 148 ms
21,272 KB
testcase_07 AC 144 ms
21,224 KB
testcase_08 AC 146 ms
21,220 KB
testcase_09 AC 17 ms
8,212 KB
testcase_10 AC 17 ms
8,180 KB
testcase_11 AC 18 ms
8,092 KB
testcase_12 AC 16 ms
8,096 KB
testcase_13 AC 17 ms
8,172 KB
testcase_14 AC 17 ms
8,124 KB
testcase_15 AC 16 ms
8,232 KB
testcase_16 AC 17 ms
8,132 KB
testcase_17 AC 17 ms
8,228 KB
testcase_18 AC 17 ms
8,184 KB
testcase_19 AC 17 ms
8,180 KB
testcase_20 AC 17 ms
8,100 KB
testcase_21 AC 17 ms
8,224 KB
testcase_22 AC 17 ms
8,164 KB
testcase_23 AC 17 ms
8,092 KB
testcase_24 AC 17 ms
8,128 KB
testcase_25 AC 17 ms
8,124 KB
testcase_26 AC 17 ms
8,056 KB
testcase_27 AC 18 ms
8,124 KB
testcase_28 AC 17 ms
8,104 KB
testcase_29 AC 17 ms
8,180 KB
testcase_30 AC 17 ms
8,060 KB
testcase_31 AC 17 ms
8,144 KB
testcase_32 AC 17 ms
8,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = 10 ** 9
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  heapq import heappop,heapify,heappush
from bisect import bisect_left

def main():
    n = int(input())
    Y = list(map(int,input().split()))
    Y.sort()
    
    if len(set(Y)) == 1:
        print(1)
        return

    ans = 0
    a = 0
    b = (n + 1)//2
    for i in range(1,n):
        ans += abs(Y[i] - Y[b])

    tmp = ans
    if n%2 == 0:
        for i in range(1,n - 1):
            if i%2 == 1:
                tmp += -Y[a] + 2 * Y[i] - Y[b]
                a += 1
                b += 1
            else:
                tmp += -Y[a] + 2 * Y[i] - Y[b] 
            ans = min(tmp,ans)
    
    else:
        for i in range(1,n - 1):
            if i%2 == 1:
                tmp += -Y[a] + 2 * Y[i] - Y[b]
                a += 1
            else:
                tmp += -Y[a] + 2 * Y[i] - Y[b]
                b += 1
            ans = min(ans,tmp)
    print(ans)

if __name__ == '__main__':
    main()
0