Logo
(追記) (追記ここまで)

25950번 - Longest Shortest Paths 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB211100.000%

문제

Consider $n$ axis-aligned rectangles and two vertical segments $S$ and $T$ in the plane. We assume that all corners of the rectangles and segments are in integer coordinates. We also assume that the rectangles and segments are disjoint each other, that is, no two of them intersect each other and no two of them share a boundary point. For a point $p$ in $S$ and a point $q$ in $T,ドル a path between $p$ and $q$ is a chain consisting of horizontal or vertical segments that connects $p$ and $q$ and does not intersect the interiors of the rectangles. The length of a path is the sum of the lengths of segments in the path. Thus, a shortest path between $p$ and $q$ is one whose length is the smallest among all paths between $p$ and $q$.

For every pair of a point in $S$ and a point in $T,ドル there is a shortest path between them. Let $d(p, q)$ denote the length of a shortest path between a point $p$ in $S$ and a point $q$ in $T$. Our goal is to compute the length of the longest path among all shortest paths connecting a point in $S$ and a point in $T,ドル that is, $\displaystyle\max_{p ∈ S}\max_{q ∈ T}d(p,q)$.

(a) (b)

For example, consider the figures above. Figure (a) shows two vertical segments $S$ and $T,ドル and no rectangle in the plane. Every shortest path between a point in $S$ and a point in $T$ has length at most 9ドル$. Since $d(s, t) = 9,ドル we have $\displaystyle\max_{p ∈ S}\max_{q ∈ T}d(p,q) = d(s, t) = 9$ for this example.

Figure (b) shows an axis-aligned rectangle $A$ and two vertical segments $S$ and $T$ in the plane. There are two shortest paths between a point $s$ in $S$ and a point $t$ in $T,ドル one in red color and one in blue color. Then $d(s, t) = 11$. Observe that every shortest path between a point in $S$ and a point in $T$ has length smaller than or equal to 11ドル$. Thus, we have $\displaystyle\max_{p ∈ S}\max_{q ∈ T}d(p,q) = d(s, t) = 11$ for this example.

Given $n$ axis-aligned rectangles and two vertical segments $S$ and $T$ that do not intersect each other, write a program to compute the length of the longest path among all shortest paths connecting a point in $S$ and a point in $T$.

입력

Your program is to read from standard input. The input starts with a line containing six integers. The first three integers represent the $x$-coordinate and the two $y$-coordinates of the endpoints of the vertical segment $S,ドル and the last three integers represent the $x$-coordinate and the two $y$-coordinates of the endpoints of the vertical segment $T$.

The next line contains an integer $n$ (0ドル ≤ n ≤ 5,000円$), where $n$ is the number of axis-aligned rectangles. The rectangles are numbered from 1ドル$ to $n$. In the following $n$ lines, the $i$-th line contains four nonnegative integers. The first two integers represent the $x$-coordinate and $y$-coordinate of the top-left corner of the rectangle $i,ドル and the last two integers represent the $x$-coordinate and $y$-coordinate of the bottom-right corner of the rectangle $i$.

All the coordinate values of endpoints of $S$ and $T,ドル and two corners of the rectangles are nonnegative integers no more than 10ドル^8$.

출력

Your program is to write to standard output. Print exactly one line. The line should contain the length of the longest path among all shortest paths between a point a point in $S$ and a point in $T$.

Sample input 1 corresponds to the case of Figure (a), and sample input 2 corresponds to the case of Figure (b).

제한

예제 입력 1

0 0 6 5 2 4
0

예제 출력 1

9

예제 입력 2

0 0 6 5 2 4
1
2 6 3 0

예제 출력 2

11

예제 입력 3

0 10 30 5 10 30
2
2 50 3 12
2 11 3 0

예제 출력 3

41

힌트

출처

ICPC > Regionals > Asia Pacific > Korea > Nationwide Internet Competition > Seoul Nationalwide Internet Competition 2022 H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /