結果

問題 No.837 Noelちゃんと星々2
ユーザー 👑 KazunKazun
提出日時 2021-02-07 19:53:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 466 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 109,424 KB
最終ジャッジ日時 2023-09-17 18:20:59
合計ジャッジ時間 6,203 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 80 ms
75,592 KB
testcase_11 WA -
testcase_12 AC 79 ms
75,720 KB
testcase_13 AC 78 ms
75,352 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 74 ms
71,268 KB
testcase_17 WA -
testcase_18 AC 78 ms
75,384 KB
testcase_19 AC 79 ms
75,684 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 80 ms
75,420 KB
testcase_24 AC 73 ms
71,244 KB
testcase_25 AC 73 ms
71,204 KB
testcase_26 AC 74 ms
71,224 KB
testcase_27 AC 76 ms
71,040 KB
testcase_28 AC 73 ms
71,468 KB
testcase_29 AC 74 ms
71,440 KB
testcase_30 AC 73 ms
71,048 KB
testcase_31 AC 73 ms
71,328 KB
testcase_32 AC 74 ms
71,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def dist(Y,a,b):
    X=0
    for y in Y:
        X+=min(abs(y-a),abs(y-b))
    return X

def solve(Y):
    Z=sorted(set(Y))
    M=len(Z)
    if M==1:
        return 1
    elif M==2:
        return 0

    Y.sort()

    p=M//3
    q=(M//3)*2
    A=float("inf")

    for a in range(max(p-5,0),min(p+5,M)):
        for b in range(max(q-5,0),min(q+5,M)):
            A=min(A,dist(Y,Z[a],Z[b]))
    return A

N=int(input())
Y=list(map(int,input().split()))
print(solve(Y))
0