LCC '25 Contest 2 S1 - Colourful Maze
View as PDF
Submit solution
Points:
5 (partial)
Time limit:
1.0s
Java
2.0s
Python
2.0s
Memory limit:
256M
Author:
Problem type
You are in an grid. Each cell has a colour (colours are numbered from
to
). You start at
and need to reach
.
You can move up, down, left, or right, however, on each move, the colour of the new cell you move to must be different from the colour of your current cell.
Input Specification
The first line contains .
The next lines each contain
integers, the colours of each cell in the grid.
Output Specification
Output the shortest number of moves to get from to
, or
if impossible.
Constraints
Sample Input 1
3 4 5
3 1 4 2
5 2 1 3
4 5 2 1
Output for Sample Input 1
5
Explanation of Output for Sample Input 1
One possible path is: ,
,
,
,
,
, which takes 5 moves.
Sample Input 2
3 3 2
1 2 2
2 2 2
2 1 1
Output for Sample Input 2
-1
Sample Input 3
2 4 4
1 1 4 1
2 3 3 3
Output for Sample Input 3
6
Comments