Rat Trap
CodeChefOpen on judge ↗
A rat is initially positioned at $x = 0$ on a one-dimensional line. Every second, the rat can either move one unit to the right or one unit to the left. There is a trap located at a specific point $x = x_0$ on the line. If the rat reaches this point, it gets caught in the trap and can no longer move. However, the rat can only move for a maximum of $d$ seconds. You are tasked with determining the
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start