Bridge

시간 제한1초메모리 제한2048 MB

요약
x축 단조인 단순 다각형 경로가 주어질 때, 수평 다리 하나를 놓아 그래프의 지름을 최소화하고 그 하한을 출력한다.
난이도

어려움10점 중 9점

유형
기하, 이분 탐색, 그리디
정답자
아직 제출이 없습니다

문제

You are given a simple polygonal path P=\<v_1,v_2,…,v_n>P = \<v\_1, v\_2, \dots , v\_n> with x(v_i)≤x(v_i+1)x(v\_i) ≤ x(v\_{i+1}) for every i=1,…,n−1i = 1, \dots , n − 1 in the plane. Every segment of PP has a positive length and no two segments of PP intersect, except at their endpoints. The distance between any two points pp, qq in PP is the length of the path from pp to qq along PP, that is, the sum of segment lengths of the path. The diameter of PP is the maximum of all possible distances between two points in PP.

For example, consider a polygonal path P=\<p_1,p_2,p_3>P = \<p\_1, p\_2, p\_3> as shown in Figure (a) below. The distance between the two midpoints pp, qq of the segments is the sum of lengths of segments pv_2pv\_2 and v_2qv\_2q. The diameter of PP is the distance between the two end vertices v_1v\_1, v_3v\_3 of PP, that is the sum of lengths of segments v_1v_2v\_1v\_2 and v_2v_3v\_2v\_3.

Now we add a bridge to PP. A bridge BB of PP is a segment parallel to the xx-axis and connecting two points of PP such that for every point zz of BB, except the endpoints of BB, PP has no point z′z' with x(z)=x(z′)x(z) = x(z') and y(z)≤y(z′)y(z) ≤ y(z'), where x(t)x(t) is the xx-coordinate and y(t)y(t) is the yy-coordinate of a point tt in the plane. Then a path connecting two points of PP can use BB by entering and exiting at the endpoints of BB. Thus, the distance between two points of PP is the length of the shorter path between the path using BB and the path not using BB.

For example, if we add a bridge BB as shown in Figure (b) above, the distance between v_1v\_1 and v_3v\_3 is a+e+∣B∣a + e + |B| by the path using BB, where ∣B∣|B| is the length of BB. The distance between v_1v\_1 and rr is the smaller between the length a+d+∣B∣a + d + |B| of the path using BB and the length a+b+ca + b + c of the path not using BB.

Given a simple polygonal path P=\<v_1,v_2,…,v_n>P = \<v\_1, v\_2, \dots , v\_n> with x(v_i)≤x(v_i+1)x(v\_i) ≤ x(v\_{i+1}) for every i=1,…,n−1i = 1, \dots , n − 1, write a program to output the infimum (greatest lower bound) of diameters of PP using a bridge.

입력

Your program is to read from standard input. The first line contains the number nn (3≤n≤1053 ≤ n ≤ 10^5) of vertices of P=\<v_1,v_2,…,v_n>P = \<v\_1, v\_2, \dots , v\_n> with x(v_i)≤x(v_i+1)x(v\_i) ≤ x(v\_{i+1}) for every i=1,…,n−1i = 1, \dots , n − 1. In the next nn lines, the ii-th line contains the xx-coordinate x(v_i)x(v\_i) and the yy-coordinate y(v_i)y(v\_i) of v_iv\_i (−100,000≤x(v_i),y(v_i)≤100,000−100\\,000 ≤ x(v\_i), y(v\_i) ≤ 100\\,000) . All the coordinates are integers, and no two vertices are at the same position.

출력

Your program is to write to standard output. Print the infimum zz of diameters of PP using a bridge. If no bridge can be placed on PP, print the diameter of PP with no bridge. The output zz should be in the format that consists of its integer part, a decimal point, and its fractional part, and will be decided to “correct” if it holds that ∣a−z∣a<10−6\frac{|a-z|}{a} < 10^{-6}, where aa denotes the exact answer.

예제2

  1. 예제 1

    입력
    3
    0 3
    3 0
    6 3
    
    예상 출력
    6.56301792813632
    
  2. 예제 2

    입력
    4
    0 1
    0 0
    1 0
    1 1
    
    예상 출력
    2.0