Topics

Idea

To determine the minimal number of steps, we consider the horizontal and vertical distances between the two points, denoted as and .

The key insight is that the robot can move diagonally, which allows it to reduce both and by 1 in a single step. Therefore, the number of diagonal steps is limited by the smaller of the two distances. After covering the smaller distance, the remaining distance in the larger dimension must be covered by moving in a straight line.

For example, if , the robot can move diagonally times, reducing both distances by 1 each time. This leaves a remaining vertical distance of , which requires additional steps. The total number of steps is , which is the maximum of and . Similarly, if , the total number of steps is .

Thus, the minimal number of steps is determined by the maximum of the horizontal and vertical distances

Code

inline void solve() {
  cout << max(abs(x1 - x2), abs(y1 - y2)) << endl;
}