#P9909. [COCI 2023/2024 #2] Pingvin
[COCI 2023/2024 #2] Pingvin
Problem Description
Given an cube, it is divided into unit cubes, and some of the unit cubes are obstacles and cannot be passed through.
Given the coordinates of the start and the target, in each step you can move from one unit cube to an adjacent (sharing a face) non-obstacle unit cube. Find the minimum number of steps needed to go from the start to the target.
Input Format
The first line contains an integer .
The next line contains integers , representing the starting position.
The next line contains integers , representing the target position.
Then matrices are given. In the -th layer, the cell in row and column indicates whether is an obstacle ( means obstacle).
It is guaranteed that the start and the target positions are not obstacles.
Output Format
Output one integer in a single line, representing the minimum number of steps. If it is impossible to reach, output .
2
1 1 1
1 1 2
00
10
01
00
1
3
2 3 1
1 1 1
000
010
000
111
111
111
111
111
111
3
3
2 1 1
3 2 2
000
010
110
010
001
001
101
110
000
3
Hint
Constraints
| Score | Special Property | |
|---|---|---|
| No obstacles | ||
| All cells with coordinate greater than are obstacles | ||
| None |
For all testdata, .
Translated by ChatGPT 5