시간 제한메모리 제한제출정답맞힌 사람정답 비율
1.75 초 (추가 시간 없음) 1024 MB82225.000%

문제

Help the bird Faby to navigate through a sequence of $n$ pairs of pipes, by finding the shortest line he can fly on to reach his destination. For simplicity, we represent Faby as a single point in the plane and assume every pipe has width zero. This way, the gap between every pair of pipes can be represented as an interval on the $y$ axis. The bird starts out at $s = (x_s, y_s)$ and his goal is to reach $t = (x_t, y_t)$. Find the shortest line from $s$ to $t$, passing through all intervals in between in increasing order of their $x$ coordinates.

Figure F.1: Visualisation of the second sample input. The red lines represent the intervals and the black line the shortest possible path. Faby and the black dots are the points in the output. Note that $(2, 1)$ can optionally be included in the output too.

입력

The input consists of:

  • One line with four integers $x_s, y_s, x_t$ and $y_t$ ($-10^9 \le x_s, y_s, x_t, y_t \le 10^9$), the start and end points.
  • One line with an integer $n\ (0 \le n \le 10^6)$, the number of intervals.
  • $n$ lines, the $i$th of which contains three integer $x_i, y_{i,1}$ and $y_{i,2}$ ($-10^9 \le x_i, y_{i, 1}, y_{i, 2} \le 10^9$, $y_{i, 1} < y_{i, 2}$), the intervals.

It can be assumed that $x_s < x_1 < \dots < x_n < x_t$.

출력

Output a sequence of $k$ $(2 \le k \le n+2$) points $p_1, \dots, p_k$, one per line, such that:

  • All points have integer coordinates.
  • $p_1 = s$ and $p_k = t$.
  • Let $P$ be the path obtained by connecting $\overline{p_i p_{i+1}}$ for all $1 \le i < k$. Then:
    • $P$ passes through all intervals in increasing order of their $x$ coordinates.
    • The length of $P$ is minimal.

If there are multiple valid solutions, you may output any one of them.

예제 입력 1

0 0 10 0
1
5 -10 10

예제 출력 1

0 0
10 0

예제 입력 2

0 0 10 0
4
2 1 3
4 2 3
7 0 2
9 -2 -1

예제 출력 2

0 0
4 2
9 -1
10 0

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > German Collegiate Programming Contest > GCPC 2021 F번

  • 문제를 만든 사람: Florian Leimgruber

채점 및 기타 정보

  • 이 문제의 채점 우선 순위는 2이다.