| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 4 초 | 1024 MB | 31 | 24 | 23 | 79.310% |
Recently, your car underwent a software update. Now, if you use the blinkers too much, the car shuts down, reporting a "buffer overflow", whatever that means! On the bright side, you are now welcome at the Broken-down Automobile Preservation Convention (BAPC).
You found out late, so you have to drive there as quickly as possible! Still, of course, you have to obey all traffic rules. At each intersection, you should follow these rules, regardless of whether an intersection has roads in all directions or not:
To play it safe with your blinkers, you decide you are going to activate them at most $k$ times. Luckily, you can still deactivate them at any time. This seems rather limiting, but you make one shrewd observation: as long as you keep your blinkers on (they do not turn off automatically), you can keep turning in the same direction.
The road network consists of intersections with roads between them. Roads always start and end in one of the four cardinal directions: north, east, south, or west. Furthermore, they never start and end at the same intersection. As an example, consider sample cases 1 through 3, visualized in Figure B.1. These samples only differ in their value of $k$.
Figure B.1: Visualization of the first, second, and third sample input.
To simplify navigation, you assume that each road can be traversed in the same amount of time, i.e. each road is considered to be of length 1ドル$. Find the shortest route from your current location to the BAPC, ensuring that you do not activate the blinkers more than $k$ times. From your current location, you can drive in any direction without using your blinkers.
The input consists of:
You start at intersection 1ドル,ドル and the BAPC is located at intersection $n$. Each intersection $i$ has at most one road to each other intersection $j$. If this road exists, then intersection $j$ has exactly one road to intersection $i$ as well.
If it is possible to drive from intersection 1ドル$ to $n$ using the blinkers at most $k$ times, output the length of the shortest such route. Otherwise, output "impossible".
5 2 0 2 0 0 4 0 3 1 0 4 2 0 0 5 2 3 0 0 0 4
3
5 1 0 2 0 0 4 0 3 1 0 4 2 0 0 5 2 3 0 0 0 4
4
5 0 0 2 0 0 4 0 3 1 0 4 2 0 0 5 2 3 0 0 0 4
impossible
5 2 0 2 0 0 4 0 3 1 0 4 2 0 0 0 2 3 0 0 0 0
impossible
ICPC > Regionals > Europe > Northwestern European Regional Contest > Benelux Algorithm Programming Contest > BAPC 2024 B번