| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 | 1024 MB | 3 | 1 | 1 | 33.333% |
Everyone thinks Prienai Way asteroid belt is filled with asteroids, but Lukas has a map with empty parts of the belt shown on it. In the map, asteroid belt is divided into M × N squares, each of which is either empty or full of asteroids.
Lukas wants to fly through the asteroid field. Naturally, he can only fly through empty squares.
Lukas’s spaceship can fly horizontally as long as needed, but it uses fuel to fly vertically – 1 fuel unit per each square passed vertically. Lukas’s destination is a planet in square (X2, Y2).
Figure out the smallest amount of fuel Lukas will need to consume to reach the destination.
There are two numbers on the first line: asteroid field length M and height N. Lukas’s starting coordinates X1 and Y1, and the destination planet coordinates X2 ir Y2 are presented on the second line. The third line contains a single integer K – the number of empty regions.
Each of the following K lines consist of three natural numbers: hi, ai, bi, meaning that in hi-th row of the asteroid belt squares from ai to bi inclusively are free.
Both the starting point and the destination belongs to one of the K empty regions. No pair of empty regions that are on the same row touch or cross.
Output one integer – lowest possible amount of fuel needed to reach the destination. If it is impossible to reach the destination, output -1.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 7 | 1 ≤ M ≤ 10, 1 ≤ N ≤ 4, 1 ≤ K ≤ 10 |
| 2 | 31 | 1 ≤ M ≤ 1 000, 1 ≤ N ≤ 1 000, 1 ≤ K ≤ 2 000 |
| 3 | 23 | 1 ≤ M ≤ 2 000, 1 ≤ N ≤ 2 000, 1 ≤ K ≤ 100 000 |
| 4 | 39 | 1 ≤ M ≤ 1 000 000 000, 1 ≤ N ≤ 10 000, 1 ≤ K ≤ 100 000 |
6 7 2 1 2 6 8 1 1 3 5 4 4 2 3 3 3 3 6 4 4 4 4 6 6 6 2 4 7 4 4
5
Olympiad > Lithuanian Olympiad in Informatics > Lithuanian Olympiad in Informatics 2015/2016 > National Round (2) > 10-12 Classes 4번