Anti-Distance
Time limit2sMemory limit256 MB
Given two free cells on a grid where every fifth cell at (2i+j, i-2j) is blocked, find the fewest side-adjacent steps between them.
- Level
Medium7 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Consider a plane divided into unit squares with side . Choose a square and draw coordinate axes from its center, parallel to its sides.
Each fifth square contains an obstacle. The obstacles are placed in every square whose center is at for all integers and . All other squares are free.
Amelia stands in a free square and wants to move to a free square . In one step, she can move from her square to a neighbor that shares a side with it, but only if that neighbor is free. What is the minimum number of steps Amelia must make to reach ?
Input
The first line contains two integers and , the coordinates of the starting square . The second line contains two integers and , the coordinates of the destination square . All coordinates are between and . Both squares are guaranteed to be free.
Output
Print one integer: the minimum number of steps from square to square .