No.1412 Super Ryuo
Problem Statement
There is a board extending infinitely in the vertical and horizontal directions, as shown in the figure below.
A piece called "Super Ryuo" is on square $(A, B)$ of this board.
In one move, this piece can perform one of the following movements.
- Move like a "Rook".
Formally, if the square before the move is $(X, Y)$, choose any integer $Z$ and move to $(Z, Y)$ or $(X, Z)$. - Move by $1$ square vertically or horizontally, up to $3$ times.
Formally, if the square before the move is $(X, Y)$, choose any pair of integers $Z, W$ such that $|X - Z| + |Y - W| \leq 3$ and move to $(Z, W)$.
Find the minimum number of moves required for this piece to reach square $(C, D)$.
Input
$A\ B\ C\ D$
- $-10^9 \leq A, B, C, D \leq 10^9$
- $(A, B) \neq (C, D)$
- $A, B, C, D$ are integers
Output
Print the answer as an integer, followed by a newline.
Sample
Sample 1
Input
1 1 2 3
Output
1
From $(1, 1)$, you can reach $(2, 3)$ in $1$ move by moving by $1$ square vertically or horizontally $3$ times.
Sample 2
Input
1 1 2 -1000000000
Output
2
The destination cannot be reached in $1$ move, but it can be reached in $2$ moves, for example, by performing the movement described in Sample 1 and then moving like a Rook.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
evima
37zigen