logo AlgoBeat OnlineJudge
登录 注册

#214406. [ICPC 2025 WF] Walking on Sunshine

内存限制:2048 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

I'm walking on sunshine, and it don't feel good – my eyes hurt!

Baku has plenty of sunshine. If you walk away from the sun, or at least perpendicular to its rays, it does not shine in your eyes. For this problem assume that the sun shines from the south. Walking west or east or in any direction between west and east with a northward component avoids looking into the sun. Your eyes will hurt if you walk in any direction with a southward component.

Baku also has many rectangular areas of shade, and staying in these protects your eyes regardless of which direction you walk in. For example, Figure L.1 shows two shaded areas.

Find the minimum distance you need to walk with the sun shining in your eyes to get from the contest location to the awards ceremony location.

:::align{center}

Figure L.1: Sample Input 1 and a path that minimizes the sun shining in your eyes. :::

输入格式

The first line of input contains five integers , , , , and , where () is the number of shaded areas, is the location of the contest, and is the location of the awards ceremony (). The sun shines in the direction from south towards north. You look into the sun if you walk in direction for any and any .

The next lines describe the shaded areas, which are axis-aligned rectangles. Each of these lines contains four integers , , , and (; ). The southwest corner of the rectangle is and its northeast corner is . The rectangles describing the shaded areas do not touch or intersect.

输出格式

Output the minimum distance you have to walk with the sun shining in your eyes. Your answer must have an absolute or relative error of at most .

样例

样例输入 1

2 1 7 5 1
3 6 5 9
2 3 6 5

样例输出 1

3.0

样例输入 2

2 0 10 10 0
2 7 3 8
4 3 8 5

样例输出 2

7.0

样例输入 3

2 11 -1 -1 11
2 7 3 8
4 3 8 5

样例输出 3

0.0

样例输入 4

3 1 5 9 5
-5 6 2 9
4 7 12 8
1 1 7 3

样例输出 4

0.0

样例输入 5

3 1 7 9 3
2 6 3 8
4 4 5 6
6 2 7 4

样例输出 5

0.0

样例输入 6

1 0 0 0 0
-5 -5 5 5

样例输出 6

0.0

数据范围与提示

Explanation of Sample 1: Figure L.1 shows an optimal path from the contest location to the awards ceremony location with 5 segments. On the first segment you walk away from the sun. On the second and fourth segments you walk towards the sun but in a shaded area. On the third and fifth segments you walk towards the sun outside the shaded areas. The total length of these two segments is 3.