103235: [Atcoder]ABC323 F - Push and Carry
Description
Score : $525$ points
Problem Statement
Takahashi and a cargo are on a coordinate plane.
Takahashi is currently at $(X_A,Y_A)$, and the cargo is at $(X_B,Y_B)$. He wants to move the cargo to $(X_C,Y_C)$.
When he is at $(x,y)$, he can make one of the following moves in a single action.
- Move to $(x+1,y)$. If the cargo is at $(x+1,y)$ before the move, move it to $(x+2,y)$.
- Move to $(x-1,y)$. If the cargo is at $(x-1,y)$ before the move, move it to $(x-2,y)$.
- Move to $(x,y+1)$. If the cargo is at $(x,y+1)$ before the move, move it to $(x,y+2)$.
- Move to $(x,y-1)$. If the cargo is at $(x,y-1)$ before the move, move it to $(x,y-2)$.
Find the minimum number of actions required to move the cargo to $(X_C,Y_C)$.
Constraints
- $-10^{17}\leq X_A,Y_A,X_B,Y_B,X_C,Y_C\leq 10^{17}$
- $(X_A,Y_A)\neq (X_B,Y_B)$
- $(X_B,Y_B)\neq (X_C,Y_C)$
- All input values are integers.
Input
The input is given from Standard Input in the following format:
$X_A$ $Y_A$ $X_B$ $Y_B$ $X_C$ $Y_C$
Output
Print the minimum number of actions required to move the cargo to $(X_C,Y_C)$.
Sample Input 1
1 2 3 3 0 5
Sample Output 1
9
Takahashi can move the cargo to $(0,5)$ in nine actions as follows.
- Move to $(2,2)$.
- Move to $(3,2)$.
- Move to $(3,3)$. The cargo moves to $(3,4)$.
- Move to $(3,4)$. The cargo moves to $(3,5)$.
- Move to $(4,4)$.
- Move to $(4,5)$.
- Move to $(3,5)$. The cargo moves to $(2,5)$.
- Move to $(2,5)$. The cargo moves to $(1,5)$.
- Move to $(1,5)$. The cargo moves to $(0,5)$.
It is impossible to move the cargo to $(0,5)$ in eight or fewer actions, so you should print $9$.
Sample Input 2
0 0 1 0 -1 0
Sample Output 2
6
Sample Input 3
-100000000000000000 -100000000000000000 100000000000000000 100000000000000000 -100000000000000000 -100000000000000000
Sample Output 3
800000000000000003
Output
得分:525分
问题描述
高桥君和一件货物在坐标平面上。
高桥君现在在$(X_A,Y_A)$,货物在$(X_B,Y_B)$。 他想将货物移动到$(X_C,Y_C)$。
当他处于$(x,y)$时,他可以执行以下单个操作之一。
- 移动到$(x+1,y)$. 如果在移动前货物在$(x+1,y)$,则将其移动到$(x+2,y)$。
- 移动到$(x-1,y)$. 如果在移动前货物在$(x-1,y)$,则将其移动到$(x-2,y)$。
- 移动到$(x,y+1)$. 如果在移动前货物在$(x,y+1)$,则将其移动到$(x,y+2)$。
- 移动到$(x,y-1)$. 如果在移动前货物在$(x,y-1)$,则将其移动到$(x,y-2)$。
找出将货物移动到$(X_C,Y_C)$所需的最小操作数。
约束条件
- $-10^{17}\leq X_A,Y_A,X_B,Y_B,X_C,Y_C\leq 10^{17}$
- $(X_A,Y_A)\neq (X_B,Y_B)$
- $(X_B,Y_B)\neq (X_C,Y_C)$
- 所有输入值都是整数。
输入
输入从标准输入以以下格式给出:
$X_A$ $Y_A$ $X_B$ $Y_B$ $X_C$ $Y_C$
输出
打印将货物移动到$(X_C,Y_C)$所需的最小操作数。
样例输入 1
1 2 3 3 0 5
样例输出 1
9
高桥君可以通过以下方式在九个操作内将货物移动到$(0,5)$:
- 移动到$(2,2)$。
- 移动到$(3,2)$。
- 移动到$(3,3)$. 货物移动到$(3,4)$。
- 移动到$(3,4)$. 货物移动到$(3,5)$。
- 移动到$(4,4)$。
- 移动到$(4,5)$。
- 移动到$(3,5)$. 货物移动到$(2,5)$。
- 移动到$(2,5)$. 货物移动到$(1,5)$。
- 移动到$(1,5)$. 货物移动到$(0,5)$。
不可能在八个或更少的操作内将货物移动到$(0,5)$,因此你应该打印$9$。
样例输入 2
0 0 1 0 -1 0
样例输出 2
6
样例输入 3
-100000000000000000 -100000000000000000 100000000000000000 100000000000000000 -100000000000000000 -100000000000000000
样例输出 3
800000000000000003