luogu#P1852. 跳跳棋

    ID: 5907 Type: RemoteJudge 1000ms 125MiB Tried: 6 Accepted: 4 Difficulty: 8 Uploaded By: Tags>二分答案最近公共祖先LCA清华集训

跳跳棋

Problem Description

Jumping Checkers is played on a number line. Pieces can only be placed on integer points. No position may contain more than one piece.

We use Jumping Checkers to play a simple game: there are 33 pieces on the board at positions a,b,ca,b,c. We want to move them, using the fewest jumps, so that their positions become x,y,zx,y,z. (The pieces are indistinguishable.)

The rule for a jump is simple: choose any piece and jump it over a pivot piece. After the jump, the distance between the two pieces remains unchanged. Each move may jump over exactly 11 piece.

Write a program to first determine whether the task is possible. If it is, output the minimum number of jumps required.

Input Format

The first line contains three integers, the current positions a,b,ca,b,c (pairwise distinct).

The second line contains three integers, the target positions x,y,zx,y,z (pairwise distinct).

Output Format

If there is no solution, output a single line NO.

If it is reachable, output the first line YES, and the second line the minimum number of jumps.

1 2 3
0 3 5
YES
2

Hint

Constraints

  • For 20%20\% of the testdata, the absolute value of each input integer does not exceed 1010.
  • For 40%40\% of the testdata, the absolute value of each input integer does not exceed 1000010000.
  • For 100%100\% of the testdata, the absolute value does not exceed 10910^9.

Translated by ChatGPT 5