Segment Drawing
시간 제한5초메모리 제한2048 MB
각 점에서 정해진 x축 위의 선분까지 새 선분을 하나씩 그어 서로 교차하지 않게 할 때, 전체 길이의 최솟값을 구하거나 불가능하면 -1을 출력한다.
문제
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 drawn segment must connect point to its corresponding line segment . The correspondence between point and line segment 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 (), which is the number of given point/line segment pairs.
Each of the next lines contains four integers ). This denotes a point at and its corresponding line segment with endpoints and . 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 . If there is no way to draw the new segments without intersecting, output .