Years after leaving primary school, Lmc fondly recalled a cartoon he loved and frequently discussed with friends: Shinkansen Henkei Robo Shinkalion. In the series, hostile robots suddenly threaten the city. Hayato Hayasugi, a young elementary schooler and passionate rail enthusiast, stumbles into an attack and discovers his father's secret role at the Shinkansen Ultra Evolution Institute. Upon testing, Hayato demonstrates a remarkable 96% compatibility with the Shinkalion robots, earning a place alongside other young drivers to pilot Shinkalions against the Kitoralsus.
Among all the mechs, Lmc was particularly fascinated by Dr. Yellow’s Railgun. Inspired by his love for high-tech weaponry (a railgun fan, rather than a traditional train enthusiast), Lmc decided to build a replica of Dr. Yellow’s railgun and run a relay experiment.
Coincidentally, Lmc spotted Peppa and her $N-1$ friends playing in the park. He equipped each of the $N$ participants with a railgun, assigned them numbers $1$ through $N$, and noted their coordinates on an infinite 2D Cartesian plane.
(Fig. 1 Dr. Yellow)
(Fig. 2 Hayato Hayasugi)
In the experiment, every person initially faces $0^\circ$ (the positive $y$-axis direction). The relay unfolds sequentially:
- At time $t = 0$, person $1$ begins turning clockwise at their individual angular speed.
- The moment person $1$ points directly at person $2$, person $1$ fires their railgun, instantly hitting person $2$.
- Person $2$ immediately begins turning clockwise from $0^\circ$ toward person $3$, firing as soon as target alignment is reached.
- This chain reaction continues sequentially until person $N-1$ turns and fires at person $N$.
Calculate the total elapsed time (in seconds) from $t = 0$ until person $N$ is struck by the railgun. You are given the number of participants $N$, their coordinates $(X_i, Y_i)$, and their rotation speeds ($T_i$ seconds per $D_i$ degrees).
Input
The first line contains a single integer $N$.
The following $N$ lines each contain four space-separated integers describing the $i$-th person: $X_i, Y_i, D_i, T_i$.
Output
Output the time when person $N$ is shot by the railgun.
Your answer is considered correct if its absolute or relative error does not exceed $10^{-6}$. Formally, for your answer $a$ and expected answer $b$, it will be accepted if $\frac{|a-b|}{\max(1,b)} \le 10^{-6}$.
Constraints
For all test cases:
$2 \le N \le 1000$
$0 \le Y_i \le 10^6$
$1 \le D_i, T_i \le 10^6$
$0 \le X_1 \le X_2 \le \dots \le X_N \le 10^6$
Subtask 1 (10%): $X_1 = X_2 = \dots = X_N$ and $Y_1 < Y_2 < \dots < Y_N$
Subtask 2 (40%): $Y_1 = Y_2 = \dots = Y_N$
Subtask 3 (50%): No additional constraints
Hints
To calculate the clockwise rotation angle deg in degrees required for person $A(x_1, y_1)$ to face person $B(x_2, y_2)$ starting from $0^\circ$ (positive $y$-axis):
const double PI = acos(-1.0);
// Returns the clockwise angle in degrees from (0, 1) to vector (dx, dy)
double get_clockwise_angle(double dx, double dy) {
double rad = atan2(dx, dy); // atan2(x, y) computes angle relative to positive y-axis
double deg = rad * 180.0 / PI;
if (deg < 0) {
deg += 360.0;
}
return deg;
}
Sample Test Cases
| Input | Output | |
|---|---|---|
| 3 0 0 100 1 3 4 120 4 10 1 400 2 |
4.141985 | |
Illustration for sample 1:
|
||
| 3 0 1 100 1 1 1 100 1 2 1 100 1 |
1.800000 | |
Scoring: Per Subtask
Authored by wy23918
Appeared in WYHK 2025 Mini Contest 0 [Session 2] and WYHK 2025 Mini Contest 0