G - Push Simultaneously Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 575

問題文

平面上に N 人の高橋くんと N 個のボタンがあります。 平面上には原点があり、原点から東に x メートル進み、北に y メートル進んだ位置を座標 (x,y) で表すこととします。 i 番目 (1\leq i\leq N) の高橋くんははじめ座標 (\mathit{sx} _ i,\mathit{sy} _ i) にいます。 i 番目 (1\leq i\leq N) のボタンは座標 (\mathit{gx} _ i,\mathit{gy} _ i) にあります。

高橋くんたちはそれぞれ移動をした後、この N 個のボタンを一斉に押したいです。 各ボタンは、そのボタンがある座標にいる高橋くんだけが押すことができます。 ボタンが存在する座標に到達してからボタンを押すのに必要な時間は 0 秒です。

それぞれの高橋くんは秒速 1 メートル以下の速さで好きな方向に進むことができます。 より厳密には、i 番目の高橋くんがスタートから t 秒後にいる座標を (x _ i(t),y _ i(t)) としたとき、次の条件がすべて成り立っている必要があります。

  • x _ i(0)=\mathit{sx} _ i
  • y _ i(0)=\mathit{sy} _ i
  • すべての非負実数 t _ 0,t _ 1 について、点 (x _ i(t _ 0),y _ i(t _ 0)) と点 (x _ i(t _ 1),y _ i(t _ 1)) の距離は |t _ 0-t _ 1| 以下

高橋くんたちが目標を達成するために必要な時間を求めてください。 厳密には、次の条件を満たすことができる t の最小値を求めてください。

  • x _ i,y _ i を上の条件を満たすように適切に定めたとき、すべての整数 j\ (1\leq j\leq N) および実数 t ^ \prime\ (t ^ \prime\gt t) に対して、ある整数 i\ (1\leq i\leq N) が存在して (x _ i(t ^ \prime),y _ i(t ^ \prime))=(\mathit{gx} _ j,\mathit{gy} _ j) が成り立つ。

制約

  • 1\leq N\leq 300
  • 0\leq\mathit{sx} _ i\leq10 ^ {18}\ (1\leq i\leq N)
  • 0\leq\mathit{sy} _ i\leq10 ^ {18}\ (1\leq i\leq N)
  • 0\leq\mathit{gx} _ i\leq10 ^ {18}\ (1\leq i\leq N)
  • 0\leq\mathit{gy} _ i\leq10 ^ {18}\ (1\leq i\leq N)
  • (\mathit{sx} _ i,\mathit{sy} _ i)\neq(\mathit{sx} _ j,\mathit{sy} _ j)\ (1\leq i\lt j\leq N)
  • (\mathit{gx} _ i,\mathit{gy} _ i)\neq(\mathit{gx} _ j,\mathit{gy} _ j)\ (1\leq i\lt j\leq N)
  • (\mathit{sx} _ i,\mathit{sy} _ i)\neq(\mathit{gx} _ j,\mathit{gy} _ j)\ (1\leq i\leq N,1\leq j\leq N)
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N
\mathit{sx} _ 1 \mathit{sy} _ 1
\mathit{sx} _ 2 \mathit{sy} _ 2
\vdots
\mathit{sx} _ N \mathit{sy} _ N
\mathit{gx} _ 1 \mathit{gy} _ 1
\mathit{gx} _ 2 \mathit{gy} _ 2
\vdots
\mathit{gx} _ N \mathit{gy} _ N

出力

N 人の高橋くんが N 個のボタンを同時に押すのに必要な時間を出力せよ。 真の値と出力との相対誤差が 10 ^ {-6} 以下のとき、正解と判定される。


入力例 1

4
0 0
0 1
2 0
3 1
0 2
1 0
1 2
2 2

出力例 1

2

はじめ、高橋くんとボタンの位置関係は以下のようになっています。

1,2,3,4 番目の高橋くんが、それぞれ 1,3,2,4 番目のボタンに向かってまっすぐ動くことを考えます。

すると、高橋くんたちはそれぞれスタートから 2 秒後、\sqrt2 秒後、1 秒後、\sqrt2 秒後には対応するボタンがある座標に到着しています。

よって、スタートから 2 秒後にすべてのボタンを一斉に押すことができます。

逆に、スタートから 2 秒経つより前にすべてのボタンを一斉に押すことはできないので、2 を出力してください。

答えの真の値と出力との相対誤差が 10 ^ {-6} 以下であれば正解と判定されるため、1.9999982.00000014 などを出力してもこのケースに対する正答と判定されます。


入力例 2

3
1 4
1 5
9 2
653589793238462643 383279502884197169
399375105820974944 592307816406286208
99862803482534211 706798214808651328

出力例 2

757682516069002110.04581169374262658710741005525

入力される座標が 32\operatorname{bit} 整数におさまらない場合があることに注意してください。


入力例 3

12
4459915897 5789359311
4393259463 4247016333
4827828467 4179021045
2654035685 3406423989
1790405301 4886103164
2978675817 4818583236
5912369644 5824121992
6016882384 4165667191
4305949638 3454894060
6545166942 5390976281
4043403253 4019611554
3462096432 4117859301
3528911877 4631601790
4627979431 4814676729
3810130146 5728760563
5586470124 3310360339
3664130072 4525834271
1710246881 3750440871
3143440609 5038869551
2294021341 3965849888
6189106395 4499485672
4799619607 5151972020
6905793542 3976136296
1764267574 4525373194

出力例 3

1299999319.116399442508650717909981965254

Score : 575 points

Problem Statement

There are N people and N buttons on a plane. The plane has an origin, and the coordinates (x, y) represents the position that is x meters east and y meters north of the origin. The i‑th person (1 \le i \le N) starts at (\mathit{sx}_i,\mathit{sy}_i). The i‑th button (1 \le i \le N) is located at (\mathit{gx}_i,\mathit{gy}_i).

The people want to move and press these N buttons simultaneously. A button can be pressed only by a person who is at the same coordinate as that button. The time required to press a button after reaching its coordinate is 0 seconds.

Each person can move in any direction with speed at most 1 meter per second. More formally, if the position of the i‑th person t seconds after the start is (x_i(t), y_i(t)), all of the following must hold:

  • x_i(0) = \mathit{sx}_i;
  • y_i(0) = \mathit{sy}_i;
  • For all non‑negative real numbers t_0, t_1, the distance between (x_i(t_0), y_i(t_0)) and (x_i(t_1), y_i(t_1)) is at most |t_0 - t_1|.

Find the time required for the people to achieve the goal. Formally, find the minimum t that satisfies the following condition:

  • It is possible to set x_i and y_i under the above conditions so that, for every integer j\ (1\leq j\leq N) and every real number t ^ \prime\ (t ^ \prime\gt t), there exists an integer i\ (1\leq i\leq N) with (x _ i(t ^ \prime),y _ i(t ^ \prime))=(\mathit{gx} _ j,\mathit{gy} _ j).

Constraints

  • 1\leq N\leq 300
  • 0\leq\mathit{sx} _ i\leq10 ^ {18}\ (1\leq i\leq N)
  • 0\leq\mathit{sy} _ i\leq10 ^ {18}\ (1\leq i\leq N)
  • 0\leq\mathit{gx} _ i\leq10 ^ {18}\ (1\leq i\leq N)
  • 0\leq\mathit{gy} _ i\leq10 ^ {18}\ (1\leq i\leq N)
  • (\mathit{sx} _ i,\mathit{sy} _ i)\neq(\mathit{sx} _ j,\mathit{sy} _ j)\ (1\leq i\lt j\leq N)
  • (\mathit{gx} _ i,\mathit{gy} _ i)\neq(\mathit{gx} _ j,\mathit{gy} _ j)\ (1\leq i\lt j\leq N)
  • (\mathit{sx} _ i,\mathit{sy} _ i)\neq(\mathit{gx} _ j,\mathit{gy} _ j)\ (1\leq i\leq N,1\leq j\leq N)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N
\mathit{sx}_1 \mathit{sy}_1
\mathit{sx}_2 \mathit{sy}_2
\vdots
\mathit{sx}_N \mathit{sy}_N
\mathit{gx}_1 \mathit{gy}_1
\mathit{gx}_2 \mathit{gy}_2
\vdots
\mathit{gx}_N \mathit{gy}_N

Output

Print the time required for the N people to press the N buttons simultaneously. Your output is considered correct if the relative error from the true value is at most 10^{-6}.


Sample Input 1

4
0 0
0 1
2 0
3 1
0 2
1 0
1 2
2 2

Sample Output 1

2

Initially, the positions of the people and buttons are as shown below.

Suppose persons 1,2,3,4 move straight toward buttons 1,3,2,4, respectively.

They reach their respective buttons after 2, \sqrt2, 1, and \sqrt2 seconds.

Thus, all buttons can be pressed simultaneously 2 seconds after the start.

Conversely, they cannot press all buttons simultaneously earlier than 2 seconds, so print 2.

Because an output is accepted if its relative error from the true value is at most 10^{-6}, outputs such as 1.999998 or 2.00000014 are also considered correct for this test case.


Sample Input 2

3
1 4
1 5
9 2
653589793238462643 383279502884197169
399375105820974944 592307816406286208
99862803482534211 706798214808651328

Sample Output 2

757682516069002110.04581169374262658710741005525

Note that the input coordinates may not fit in 32‑bit integers.


Sample Input 3

12
4459915897 5789359311
4393259463 4247016333
4827828467 4179021045
2654035685 3406423989
1790405301 4886103164
2978675817 4818583236
5912369644 5824121992
6016882384 4165667191
4305949638 3454894060
6545166942 5390976281
4043403253 4019611554
3462096432 4117859301
3528911877 4631601790
4627979431 4814676729
3810130146 5728760563
5586470124 3310360339
3664130072 4525834271
1710246881 3750440871
3143440609 5038869551
2294021341 3965849888
6189106395 4499485672
4799619607 5151972020
6905793542 3976136296
1764267574 4525373194

Sample Output 3

1299999319.116399442508650717909981965254