#P1747. Dual Horse Journey
Dual Horse Journey
Dual Horse Journey
Two unusual horses are playing a game on a board similar to chess. Initially, one horse is at point \((x_1,y_1)\) and the other at \((x_2,y_2)\). Both horses must reach the destination \((1,1)\) in the minimum number of moves. Unlike standard chess knights, these horses can move in two different ways:
- Knight Move ("\(\text{走日}\)" move): They can jump in an L-shape. In one move, a horse can change its position by either \((\pm2, \pm1)\) or \((\pm1, \pm2)\).
- Elephant Move ("\(\text{走田}\)" move): A horse can also move exactly two steps diagonally, i.e. from \((x, y)\) to \((x \pm 2, y \pm 2)\).
Note that a move is only valid if after moving both coordinates remain \(> 0\) (i.e. \(x>0\) and \(y>0\)).
Your task is to determine the minimum total number of moves required for both horses to reach \((1,1)\). Each horse moves independently using any combination of the allowed moves.
If a horse is already at \((1,1)\), it requires \(0\) moves.
inputFormat
The input consists of a single line containing four space-separated positive integers:
x1 y1 x2 y2
Here, \((x_1, y_1)\) and \((x_2, y_2)\) are the starting coordinates of the two horses.
outputFormat
Output a single integer: the sum of the minimum moves required for the first horse and the second horse to reach \((1,1)\).
sample
3 3 3 3
2