結果

問題 No.837 Noelちゃんと星々2
ユーザー 👑 KazunKazun
提出日時 2021-01-29 18:07:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 410 bytes
コンパイル時間 1,007 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 92,604 KB
最終ジャッジ日時 2023-09-09 11:49:44
合計ジャッジ時間 6,716 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 78 ms
75,784 KB
testcase_11 WA -
testcase_12 AC 75 ms
75,604 KB
testcase_13 AC 75 ms
75,428 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 70 ms
71,324 KB
testcase_17 WA -
testcase_18 AC 74 ms
75,576 KB
testcase_19 AC 76 ms
75,736 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 79 ms
75,452 KB
testcase_24 AC 70 ms
71,380 KB
testcase_25 AC 72 ms
71,216 KB
testcase_26 AC 70 ms
71,420 KB
testcase_27 AC 71 ms
71,072 KB
testcase_28 AC 71 ms
71,224 KB
testcase_29 AC 70 ms
71,076 KB
testcase_30 AC 71 ms
71,216 KB
testcase_31 AC 71 ms
71,348 KB
testcase_32 AC 70 ms
71,220 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):
    if min(Y)==max(Y):
        return 1

    Y.sort()

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

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

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