結果

問題 No.837 Noelちゃんと星々2
ユーザー daku9640daku9640
提出日時 2019-06-14 22:22:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 765 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 34,788 KB
最終ジャッジ日時 2024-04-26 17:10:48
合計ジャッジ時間 7,137 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    n = int(input())
    Y = sorted(map(int, input().split()))
    def f(i, j):
        ans = 0
        for k in range(n):
            if k != i and k != j:
                ans += abs(Y[i] - Y[k]) if abs(Y[i] - Y[k]) < abs(Y[j] - Y[k]) else abs(Y[j] - Y[k])
        return ans
    len_set_Y = len(set(Y))
    if len_set_Y == 1:
        return 1
    if len_set_Y == 2 or n == 2:
        return 0
    l = int(n / 2 / 2)
    r = int(n / 2 + l)
    ans = f(l, r)
    next_ans = int(1e10)
    while ans != next_ans:
        ll = (l // 2)
        lr = (l + r) // 2
        rr = (r + n) // 2
        for i, j in ((ll, r), (lr, r), (l, lr), (l, rr)):
            next_ans = min(next_ans, f(i, j))
        ans = min(ans, next_ans)
    return ans
print(solve())
0