RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
문제 ICPC00133

D. Crossing the Railways

설명

Isona is in a train station. This station has two platforms, and between them there are \(m\) parallel railways that can be viewed as infinite straight lines. Each railway is identified with an integer from 1 to \(m\), railway 1 being the closest to the first platform and railway \(m\) being the farthest. There is a 1 meter distance between consecutive railways, as well as between each platform and its closest railway. Isona is standing on the inner border of the first platform, when she realizes that she forgot to validate her ticket! There is a validating machine on the second platform, exactly opposite her current position (thus, the distance between Isona and the validating machine is \(m + 1\) meters). There are only \(s\) seconds left to validate the ticket and the bridge designated to cross the railways is too far from the validating machine. Therefore, Isona (who is very brave and a little bit careless) will cross the railways running in a straight line perpendicular to the railways themselves. Isona can only run forward (not backward) and she can stay still. When she runs at maximum speed, she needs \(v\) seconds to traverse 1 meter. She can run at any speed less than or equal to her maximum speed. There is only one problem: \(n\) trains are programmed to transit through the railways. The \(i-th\) train will use the railway \(r_{i}\). It will start crossing the straight line between Isona and the validating machine \(a_{i}\) seconds from now and it will end \(b_{i}\) seconds from now. Of course, Isona cannot cross a railway when a train is passing. Formally, for every \(i = 1\), 2, . . . , \(n\), Isona is not allowed to be on railway \(r_{i}\) at any time \(t\) with \(a_{i} < t < b_{i}\) (but she is allowed to cross at times \(a_{i}\) or \(b_{i}\)). The following picture summarizes the situation. In the picture there are \(m = 4\) railways and two trains are visible; the train going through railway 3 is currently crossing the line between Isona and the validating machine. isona isona isona isona isona validating machine validating machine validating machine validating machine validating machine 1 m Isona is a really good runner, but she gets tired every time she has to change her running speed. What is the minimum number of speed changes she has to perform to get to the validating machine on the other platform within \(s\) seconds from now? Note that at the beginning Isona is not running. She can start to run anytime. The instant she starts to run (i.e. her speed becomes positive) is not counted as a speed change. Problem D: Crossing the Railways SWERC \(2022-2023\)

제약
입력 형식

The first line of the input contains four integers \(n\), \(m\), \(s\), \(v\) (\(1 \le n \le 500\), \(1 \le m \le 10\), \(1 \le s\), \(v \le 10^{9}\)) — the number of trains, the number of railways, the maximum time in seconds Isona can spend crossing the railways, and the number of seconds she needs to traverse 1 meter at maximum speed. Each of the next \(n\) lines contains three integers \(a_{i}\), \(b_{i}\), \(r_{i}\) (\(1 \le a_{i} < b_{i} \le 10^{9}\), \(1 \le r_{i} \le m\)) — the start and end times of the \(i-th\) train crossing the straight line between Isona and the validating machine, and the railway it will be using. It is guaranteed that, for any two trains \(i\) and \(j\) that go through the same railway (i.e. \(r_{i} = r_{j}\)), there is at least 1 second between them (that is, either \(a_{j} \ge b_{i} + 1\) or \(a_{i} \ge b_{j} + 1\)).

출력 형식

Print the minimum number of speed changes Isona has to perform to get to the validating machine in time. If this is impossible, pri\(nt - 1\).

예제 1
입력
4 3 5 1
1 2 1
3 4 1
2 3 2
3 4 3
출력
0
예제 2
입력
3 3 12 2
2 10 1
1 6 2
8 12 3
출력
2
예제 3
입력
8 4 13 2
1 4 1
5 13 1
1 5 2
6 13 2
1 9 3
10 13 3
1 10 4
11 13 4
출력
2
예제 4
입력
1 1 2 2
1 2 1
출력
-1
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC SWERC 2022

평가 및 의견

D. Crossing the Railways

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

D. Crossing the Railways

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8