eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Huge Knight

Huge Knight

You have a chessboard of size \textbf{N}×\textbf{N}. The rows and columns are numbered from \textbf{1} to \textbf{N}. In a cell located at row \textbf{R1} and column \textbf{C1}, a knight is starting his journey. The knight wants to go to the cell located at row \textbf{R2} and column \textbf{C2}. Move the knight from the starting cell to this destination cell with minimum number of moves. As a reminder, a knight's jump moves him \textbf{2} cells along one of the axes, and \textbf{1} cell along the other one. In other words, if a knight is at (\textbf{A}, \textbf{B}), it may move to (\textbf{A-2}, \textbf{B-1}), (\textbf{A-2}, \textbf{B+1}), (\textbf{A+2}, \textbf{B-1}), (\textbf{A+2}, \textbf{B+1}), (\textbf{A-1}, \textbf{B-2}), (\textbf{A+1}, \textbf{B-2}), (\textbf{A-1}, \textbf{B+2}) or (\textbf{A+1}, \textbf{B+2}). Of course, the knight cannot leave the board. Given \textbf{N}, \textbf{R1}, \textbf{C1}, \textbf{R2} and \textbf{C2}, determine the minimum number of steps necessary to move the knight from (\textbf{R1}, \textbf{C1}) to (\textbf{R2}, \textbf{C2}). \InputFile The first input line contains a positive integer, \textbf{T}, indicating the number of test cases. Each case consists of a line containing five integers \textbf{N} (\textbf{3} ≤ \textbf{N} ≤ \textbf{10^15}), \textbf{R1}, \textbf{C1}, \textbf{R2} and \textbf{C2} are between \textbf{1} and \textbf{N} inclusive. \OutputFile For each test case, output the minimum number of steps needed to move the knight from (\textbf{R1}, \textbf{C1}) to (\textbf{R2}, \textbf{C2}). Assume that there will always be a solution, i.e., it’s possible to move the knight from its starting cell to its destination cell.
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
2
5 1 1 2 3
5 1 1 2 2
Вихідні дані #1
1
4
Джерело ACM-ICPC Malaysia al-Khawārizmī Programming Contest 2011