Segment Drawing

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

요약
각 점에서 정해진 x축 위의 선분까지 새 선분을 하나씩 그어 서로 교차하지 않게 할 때, 전체 길이의 최솟값을 구하거나 불가능하면 -1을 출력한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 기하, 분할 정복, 정렬
정답자
아직 제출이 없습니다

문제

You're given some points, paired with an equal number of line segments. All points are strictly above the x-axis. Each line segment lies completely on the x-axis. None of the line segments share any common points.

You would like to draw some new line segments -- one for each given point/line segment pair. The ithi^{\text{th}} drawn segment must connect point ii to its corresponding line segment ii. The correspondence between point ii and line segment ii is fixed, you cannot rearrange which point connects to which line segment.

No two drawn segments may strictly intersect, but it is allowed to have one drawn segment touching another drawn segment at an endpoint.

You would like to find the minimum total length of all drawn segments, or determine that it is impossible to draw such segments.

입력

The first line contains a single integer nn (1≤n≤1051 \le n \le 10^5), which is the number of given point/line segment pairs.

Each of the next nn lines contains four integers x,y,l,rx, y, l, r (−106≤x≤106,0<y≤106,−106≤l≤r≤106(-10^6 \le x \le 10^6, 0 < y \le 10^6, -10^6 \le l \le r \le 10^6). This denotes a point at (x,y)(x, y) and its corresponding line segment with endpoints (l,0)(l, 0) and (r,0)(r, 0). The line segments will be given in order from left to right. No two given line segments will share a common point. It is possible for two points to be at the same location.

출력

Output a single real number, which is the minimum total length of all drawn segments. The answer will be accepted if it is within an absolute or relative error of at most 10−610^{-6}. If there is no way to draw the new segments without intersecting, output −1-1.

예제3

  1. 예제 1

    입력
    3
    0 6 -4 -2
    -2 1 -1 0
    0 4 1 4
    
    예상 출력
    11.9995169566
    
  2. 예제 2

    입력
    3
    0 6 -4 -2
    0 4 -1 0
    -2 1 1 4
    
    예상 출력
    -1
    
  3. 예제 3

    입력
    2
    0 5 -1000000 -1
    0 5 1 1000000
    
    예상 출력
    10.1980390272