OTHS Coding Competition 3 (Mock CCC) S1 - The 5th Laboratory

View as PDF

Submit solution

Points: 5
Time limit: 3.0s
Memory limit: 512M

Author:
Problem types

The Elric brothers, Edward and Alphonse, have suspicions of sinister, illegal experiments occurring in the "abandoned" 5th Laboratory given by coordinates X_l, Y_l, and Z_l.

Driven by their pursuit of the truth, the boys construct a risky plot: while their allies distract the guards, they will stealthily infiltrate the lab from a hiding spot.

To ensure their success, they turn to you, an expert state programmer working alongside alchemists. Your task is to compute the minimum time t it would take them to reach the lab.

There are N hiding spots nearby with coordinates of hiding spot i represented by X_i, Y_i, and Z_i.

When on equal elevation as the lab, the boys can run at a speed of 2 units/second. If their elevation Z_i is lower than the lab, they must climb vertically upward at a speed of 1 unit/second. If their elevation is above the lab, they must glide using forwards and downward velocities of exactly 3 and 4 units/second respectively.

The boys can only glide, as free falling is not stylish. However, they do not necessarily need to glide straight.

In addition, the boys can only carry either gliders or climbing gear, but not both, as carrying both would be too heavy (Edward is too weak).

Constraints

1 \le N \le 10^6

-10^4 \le X_l,Y_l,Z_l,X_i,Y_i,Z_i \le 10^4

Input Specification

The first line contains three integers, X_l, Y_l, and Z_l representing the coordinates of the lab.

The second line contains a positive integer N, representing the number of hiding spots.

The next N lines each contain three integers X_i, Y_i, and Z_i, representing the coordinates of hiding spot i.

Output Specification

Output a single line containing a single number: the minimum time needed to reach the lab.

Note: Outputs within \pm10^{-4} relative error of the official solution will be accepted.

Sample Input 1

1 1 1
2
5 4 1
1 2 -5

Sample Output 1

2.5

Explanation for Sample 1

The first hiding spot, the brothers run \sqrt{4^2 + 3^2} or 5 meters at a speed of 2 units/second taking 2.5 seconds.

The second hiding spot, the brothers climb for 6 meters at 1 unit/second and run 1 meter at 2 units/second taking 6.5 seconds in total.

The faster of the two being 2.5 seconds.

Sample Input 2

1 1 1
2
1 2 1
1 1 1

Sample Output 2

0

Explanation for Sample 2

The optimal hiding spot is already in the lab.

Sample Input 3

0 0 0
2
0 7 4
0 3 8

Sample Output 3

2

Explanation for Sample 3

The first and second hiding spots take 3 and 2 seconds respectively.


Comments

There are no comments at the moment.