結果

問題 No.2248 max(C)-min(C)
ユーザー FromBooskaFromBooska
提出日時 2023-05-03 14:22:20
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,648 bytes
コンパイル時間 761 ms
コンパイル使用メモリ 82,240 KB
実行使用メモリ 76,784 KB
最終ジャッジ日時 2024-05-01 13:41:45
合計ジャッジ時間 9,910 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
60,720 KB
testcase_01 AC 34 ms
53,192 KB
testcase_02 AC 35 ms
53,268 KB
testcase_03 AC 91 ms
76,200 KB
testcase_04 AC 86 ms
75,940 KB
testcase_05 AC 66 ms
73,284 KB
testcase_06 AC 118 ms
76,432 KB
testcase_07 AC 121 ms
76,356 KB
testcase_08 AC 125 ms
76,548 KB
testcase_09 AC 135 ms
76,784 KB
testcase_10 AC 70 ms
73,464 KB
testcase_11 AC 127 ms
76,676 KB
testcase_12 AC 94 ms
76,392 KB
testcase_13 AC 107 ms
76,464 KB
testcase_14 AC 130 ms
76,732 KB
testcase_15 AC 127 ms
76,648 KB
testcase_16 AC 90 ms
76,088 KB
testcase_17 AC 121 ms
76,580 KB
testcase_18 TLE -
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 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 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)


0