#abc323f. F - Push and Carry

F - Push and Carry

Score : 525525 points

问题描述

高桥和一件货物在一个坐标平面上。

目前,高桥位于坐标 (XA,YA)(X_A,Y_A),而货物位于坐标 (XB,YB)(X_B,Y_B)。他希望将货物移动到坐标 (XC,YC)(X_C,Y_C)

当他在坐标 (x,y)(x,y) 时,他可以在一个动作中执行以下四种移动之一:

  • 移动到 (x+1,y)(x+1,y)。如果在移动前货物位于 (x+1,y)(x+1,y),则将其移动到 (x+2,y)(x+2,y)
  • 移动到 (x1,y)(x-1,y)。如果在移动前货物位于 (x1,y)(x-1,y),则将其移动到 (x2,y)(x-2,y)
  • 移动到 (x,y+1)(x,y+1)。如果在移动前货物位于 (x,y+1)(x,y+1),则将其移动到 (x,y+2)(x,y+2)
  • 移动到 (x,y1)(x,y-1)。如果在移动前货物位于 (x,y1)(x,y-1),则将其移动到 (x,y2)(x,y-2)

求解将货物移动到 (XC,YC)(X_C,Y_C) 所需的最小动作次数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Takahashi and a cargo are on a coordinate plane.

Takahashi is currently at (XA,YA)(X_A,Y_A), and the cargo is at (XB,YB)(X_B,Y_B). He wants to move the cargo to (XC,YC)(X_C,Y_C).

When he is at (x,y)(x,y), he can make one of the following moves in a single action.

  • Move to (x+1,y)(x+1,y). If the cargo is at (x+1,y)(x+1,y) before the move, move it to (x+2,y)(x+2,y).
  • Move to (x1,y)(x-1,y). If the cargo is at (x1,y)(x-1,y) before the move, move it to (x2,y)(x-2,y).
  • Move to (x,y+1)(x,y+1). If the cargo is at (x,y+1)(x,y+1) before the move, move it to (x,y+2)(x,y+2).
  • Move to (x,y1)(x,y-1). If the cargo is at (x,y1)(x,y-1) before the move, move it to (x,y2)(x,y-2).

Find the minimum number of actions required to move the cargo to (XC,YC)(X_C,Y_C).

Constraints

  • 1017XA,YA,XB,YB,XC,YC1017-10^{17}\leq X_A,Y_A,X_B,Y_B,X_C,Y_C\leq 10^{17}
  • (XA,YA)(XB,YB)(X_A,Y_A)\neq (X_B,Y_B)
  • (XB,YB)(XC,YC)(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:

XAX_A YAY_A XBX_B YBY_B XCX_C YCY_C

Output

Print the minimum number of actions required to move the cargo to (XC,YC)(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)(0,5) in nine actions as follows.

  • Move to (2,2)(2,2).
  • Move to (3,2)(3,2).
  • Move to (3,3)(3,3). The cargo moves to (3,4)(3,4).
  • Move to (3,4)(3,4). The cargo moves to (3,5)(3,5).
  • Move to (4,4)(4,4).
  • Move to (4,5)(4,5).
  • Move to (3,5)(3,5). The cargo moves to (2,5)(2,5).
  • Move to (2,5)(2,5). The cargo moves to (1,5)(1,5).
  • Move to (1,5)(1,5). The cargo moves to (0,5)(0,5).

It is impossible to move the cargo to (0,5)(0,5) in eight or fewer actions, so you should print 99.

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

update @ 2024/3/10 01:45:18