You can find the problem statement here.

Let 𝑓𝑥 denote the maximum number of jumps on any path to 𝑥. We wish to show that if 𝑦[𝑥,𝑥+𝐷], 𝑓𝑦𝑓𝑥+1. As a consequence, every block of 𝐷 values will only take on two distinct values, which greatly reduces the complexity of our problem.


Proof: We will do a proof by contradiction. Assume 𝑓𝑦>𝑓𝑥+1. Let 𝑋 be a trajectory to 𝑥 that takes 𝑓𝑥 jumps, and 𝑌 be a trajectory to 𝑦 that takes 𝑓𝑦 jumps. Also, let 𝑔𝑋 and 𝑔𝑌 denote the number of single-steps taken by 𝑋 and 𝑌 respectively. Then, note that our above inequality is equivalent to 𝑔𝑋𝑔𝑌+𝐷. We now wish to show that given this condition, there must exist an intersection between 𝑋 and 𝑌 such that prior to that intersection, 𝑌 uses one more jump than 𝑋.

An example of one such intersection is shown by the red line.

If such an intersection exists, we can swap the section of 𝑌 before the intersection with the section of 𝑋, thereby increasing 𝑓𝑋 by 1 and contradicting our assumption.

Consider the following algorithm to find such an intersection:

step_balance = 0
balance = 0
start trajectories X and Y at 0
while step_balance < D:
	if Y_pos <= X_pos:
		advance Y
		^ if single step, --step_balance, --balance
		^ else, balance -= D
	else:
		advance X
		^ if single step, ++step_balance, ++balance
		^ else, balance += D

I claim that this algorithm will always terminate with 𝑋 and 𝑌 at the same position---that is, balance will equal 0.

First, note that the program will definitely terminate and always with step_balance = D.

Furthermore, note that step_balance and balance are always congruent modulo 𝐷.

Finally, note the following two properties of the above algorithm:

  • If 𝑋 was the last trajectory advanced, balance > -D.
  • If the last step 𝑋 took was a single step, balance <= 0.

Therefore, if step_balance = D, the only viable value of balance is 0.