結果
| 問題 |
No.2248 max(C)-min(C)
|
| コンテスト | |
| ユーザー |
FromBooska
|
| 提出日時 | 2023-05-03 14:22:20 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,648 bytes |
| コンパイル時間 | 362 ms |
| コンパイル使用メモリ | 82,560 KB |
| 実行使用メモリ | 232,452 KB |
| 最終ジャッジ日時 | 2024-11-21 18:26:33 |
| 合計ジャッジ時間 | 130,452 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 WA * 1 TLE * 28 |
ソースコード
# Ciは3項の選択がある
# ある値を決め打って、一番近いmin、一番近いmaxを探したらどうか
# 三分探索で最小値探索
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
for i in range(N):
temp = []
temp.append(A[i])
temp.append(B[i])
temp.append((A[i]+B[i])//2)
temp.sort()
C.append(temp)
def check(X):
mn = 10**10
mx = -1
for i in range(N):
temp = C[i]
if X <= (temp[0]+temp[1])/2:
mn = min(mn, temp[0])
mx = max(mx, temp[0])
elif (temp[1]+temp[2])/2 <= X:
mn = min(mn, temp[2])
mx = max(mx, temp[2])
else:
mn = min(mn, temp[1])
mx = max(mx, temp[1])
return (mx-mn)
#for x in range(1, 20):
# print(x, check(x))
# 谷、つまり1極値を求める三分探索での解き方
# https://roiti46.hatenablog.com/entry/2015/04/29/yukicoder_No.198_%E3%82%AD%E3%83%A3%E3%83%B3%E3%83%87%E3%82%A3%E3%83%BC%E3%83%BB%E3%83%9C%E3%83%83%E3%82%AF%E3%82%B9%EF%BC%92
# https://qiita.com/ganyariya/items/1553ff2bf8d6d7789127
# 範囲に注意、ギリギリありえない値とする
left, right = -1, 10**20
while right-left > 2:
left_mid, right_mid = (2*left+right)//3, (left+2*right)//3
if check(left_mid) <= check(right_mid):
# 右midの方が大きいから右を右midに変える
right = right_mid
else:
left = left_mid
#print(left_mid, right_mid)
ans = min(check(left_mid), check(right_mid))
# leftとrightの間も入れる必要あるのか? ない
print(ans)
FromBooska