Sergey and Peen

View as PDF

Submit solution

Points: 13
Time limit: 30.0s
Memory limit: 125M

Author:
Problem type

Serog1sPerog1s has had enough. If he hears the Discord ping sound 1 more time, he WILL have a stroke. Day in and day out, the poor lad is constantly assaulted with an onslaught of cries for help from MichaelTham–it's gotten so bad that he has nightmares in which he helplessly drowns in an ocean filled with HELPs, @Sergeys, and <3_<3s. But no more, he says. Serog1sPerog1s knows that the only way to stop MichaelTham from pestering him is to banish him to the dark depths of #focus-mode. But to do this he requires the almighty Peen, a legendary artifact that appears only once a year, somewhere within the halls of TSS. Serog1sPerog1s has finally narrowed down the location of the Peen and sets out on a journey to obtain it. Pog! However, MichaelTham finds about his quest and places crates filled with cats and vegan treats at random spots throughout the school in hopes of distracting Serog1sPerog1s from reaching the Peen! Unpog! He hasn't got much time, so can you help find the shortest distance Serog1sPerog1s has to travel to reach the Peen while avoiding the beguiling boxes?

Input Specification

The first line of the input will contain 2 integers x_1 and y_1, representing Serog1sPerog1s's location.

The second line of the input will contain 2 integers x_2 and y_2, representing the location of the Peen.

The third line will contain an integer r denoting the number of boxes.

The next r lines will contain 4 integers denoting the r_x, r_y, (of the top-left corner), width, and height of each box.

Constraints

For all subtasks:

0 \le x_1, y_1, x_2, y_2, r_x, r_y \le 1000

10 \le width, height \le 100

10 \le r \le 15

Output Specification

The shortest distance Serog1sPerog1s has to travel, rounded to 2 decimal places. Serog1sPerog1s can travel along the edge of boxes, but cannot pass through them. This means that he can sneakily slip through 2 boxes that are perfectly adjacent to each other, as shown in Sample 1. There are also no boundaries, he can travel to negative coordinates if he needs to.

Sample Input 1

100 0
100 100
2
0 40 100 20
100 50 20 20

Sample Output 1

100.00

Explanation

enter image description here

Sample Input 2

100 0
100 100
2
0 40 101 20
100 50 20 20

Sample Output 2

109.91

Explanation

enter image description here The two boxes overlap, so Mr. Perogies cannot slip through and must go around.


Comments

There are no comments at the moment.