Investigating Quadradômeda

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

요약
연속한 별이 같은 x좌표나 y좌표를 가지는 점들이 주어질 때, 각 반지름이 다음 별까지의 거리보다 작은 양의 정수가 되도록 R1의 최댓값을 구한다.
난이도

보통10점 중 6점

유형
그리디, 수학, 동적 계획법
정답자
아직 제출이 없습니다

문제

The Society for Beyond-Earth Cosmonautics (SBC) is training its teams for the next edition of the International Challenge of Planetary Cosmonautics (ICPC).

SBC will conduct a simulated exploration of a distant galaxy called Quadrameda. For this mission, NN stars were selected for their geometrically strategic locations, and a visitation order was determined, numbered from 11 to NN. To prepare the teams, simplified models are used, in which each star is represented by a point in the plane with integer coordinates (x_i,y_i)(x\_i , y\_i).

The stars are arranged so that, for each 1≤i<N1 ≤ i < N, star ii is aligned with star i+1i + 1, that is, they share the same xx coordinate or the same yy coordinate.

The mission’s objective is to orbit each star ii along a circle of constant integer radius R_i≥1R\_i ≥ 1. During the simulation, the spacecraft orbits the current star and, upon reaching the point of the orbit closest to the next star, leaves this orbit and immediately begins orbiting the following star. For this maneuver to be possible, for each 1≤i<N1 ≤ i < N, the radius R_iR\_i must be strictly less than the Euclidean distance between stars ii and i+1i + 1.

The example below illustrates a valid orbit configuration with N=3N = 3; the stars are at the points (0,0)(0, 0), (4,0)(4, 0) and (4,4)(4, 4). In this configuration, we have R_1=1R\_1 = 1, R_2=3R\_2 = 3 and R_3=1R\_3 = 1.

Your task is to determine the largest integer value of R_1R\_1 such that it is possible to choose values R_1,R_2,…,R_NR\_1, R\_2, \dots , R\_N that satisfy all the conditions above. If no valid orbit configuration exists, report that the mission is impossible.

입력

The first line contains an integer NN (2≤N≤1052 ≤ N ≤ 10^5), the number of stars.

Each of the next NN lines contains two integers x_ix\_i and y_iy\_i (∣x_i∣,∣y_i∣≤109|x\_i |, |y\_i | ≤ 10^9), the coordinates of star ii. For each 1≤i<N1 ≤ i < N, stars ii and i+1i + 1 are aligned horizontally or vertically.

출력

Your program should produce a single line containing the largest integer value of R_1R\_1 such that a valid orbit configuration exists, or -1 if the mission is impossible.

예제3

  1. 예제 1

    입력
    3
    0 0
    4 0
    4 4
    
    예상 출력
    3
    
  2. 예제 2

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

    입력
    4
    0 0
    4 0
    4 4
    4 7
    
    예상 출력
    2