結果

問題 No.972 選び方のスコア
ユーザー ntudantuda
提出日時 2021-11-10 22:02:13
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,206 bytes
コンパイル時間 1,676 ms
コンパイル使用メモリ 86,208 KB
実行使用メモリ 111,052 KB
最終ジャッジ日時 2023-08-13 17:57:21
合計ジャッジ時間 11,488 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 101 ms
71,948 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 101 ms
71,896 KB
testcase_26 AC 102 ms
71,756 KB
testcase_27 RE -
testcase_28 AC 103 ms
71,844 KB
testcase_29 AC 103 ms
71,816 KB
testcase_30 RE -
testcase_31 AC 104 ms
71,652 KB
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from functools import lru_cache

N = int(input())
A = list(map(int, input().split()))

if N < 3:
    print(0)
    sys.exit()
A.sort()

B = [0] * (N + 1)
for i in range(N):
    B[i + 1] = B[i] + A[i]

@lru_cache(maxsize=None)
def g(x, y):
    return B[N] - B[N - y] + B[x] - B[x - y] - (2 * y) * A[x]

@lru_cache(maxsize=None)
def f(x):
    lb = 1
    ub = min(x, N - x - 1)
    t1 = (ub + 2 * lb) // 3
    t2 = -(-2 * ub - lb) // 3

    while ub - lb > 2:  # ???
        a, b, c, d = g(x, lb), g(x, t1), g(x, t2), g(x, ub)
        if a <= b <= c:  # ???
            lb = t1
        elif b >= c >= d:  # ???
            ub = t2
        else:
            break
        t1 = (ub + 2 * lb) // 3
        t2 = -(-2 * ub - lb) // 3
        i += 1
    return (max(g(x, lb), g(x, t1), g(x, t2), g(x, ub)))


lb = 1
ub = N - 2
t1 = (ub + 2 * lb) // 3
t2 = -(-2 * ub - lb) // 3
i = 0
while ub - lb > 2:
    a, b, c, d = f(lb), f(t1), f(t2), f(ub)
    if a <= b <= c:
        lb = t1
    elif b >= c >= d:
        ub = t2
    else:
        break

    t1 = (ub + 2 * lb) // 3
    t2 = -(-2 * ub - lb) // 3

#print(lb,t1,t2,ub)
#print(f(lb),f(t1),f(t2),f(ub))
ans = max(f(lb), f(t1), f(t2), f(ub))
print(ans)
0