結果
| 問題 |
No.972 選び方のスコア
|
| コンテスト | |
| ユーザー |
ntuda
|
| 提出日時 | 2021-11-10 22:02:13 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,206 bytes |
| コンパイル時間 | 287 ms |
| コンパイル使用メモリ | 82,152 KB |
| 実行使用メモリ | 106,224 KB |
| 最終ジャッジ日時 | 2024-11-21 14:29:41 |
| 合計ジャッジ時間 | 6,383 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 RE * 1 |
| other | AC * 4 RE * 28 |
ソースコード
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)
ntuda