The problem in brief
A rocket's distance from Earth after hours follows a parabola, kilometres, with the three coefficients given. The program must print the rocket's speed exactly hours after launch. "Speed at an instant" is the derivative of distance with respect to time, so the task is a one-line application of calculus. It is also a gentle first meeting with the object that drives all of deep learning: the derivative.
How you are scored
Hidden tests compare your printed number with the exact speed (the statement does not give the tolerance; printing enough decimals is the safe choice). On the sample, , , , , the expected output is , which our program reproduces exactly.
The key idea
Instantaneous speed is the limit of average speeds over shorter and shorter intervals. Between times and , the rocket covers kilometres, so its average speed is
As the extra term vanishes, leaving
Geometrically this is the slope of the tangent line to the parabola at . Note that , the starting distance, disappears: shifting the whole curve up does not change how fast it rises.
![Left: secants over 6 and 3 hours are steeper than the tangent at d = 12, whose slope 244.65 km/h is the speed. Right: the average speed over [d, d + h] equals 2ad + b + ah and converges to 244.65116 as h shrinks.](/corrections/kz-faio-2024-qual-c-flight-speed/figures/tangent.png)
Sample check: .
The full solution
a, b, c, d = map(float, sys.stdin.read().split()[:4])
v = 2 * a * d + b
print(f"{v:.10f}".rstrip("0").rstrip("."))
Reading all tokens with split() works whether the four numbers come on separate lines (as the statement says) or on one line (as the sample shows). Formatting with ten decimals then stripping trailing zeros prints 244.65116 instead of a float artefact such as 244.65115999999998.
solution.py --check compares the formula with a numerical derivative on 10 000 random inputs in the allowed range.
Results
| approach | sample | general |
|---|---|---|
| exact derivative | 244.65116 | correct |
| average speed from launch, | 125.25 | wrong: average, not instantaneous |
| average speed | 124.65 | wrong: off by |
| one-sided difference with | 254.65 | wrong: error |
| central difference with small | 244.65116 | correct up to rounding |
What to remember
- Speed is the derivative of position: the limit of , the slope of the tangent.
- Derivative of a polynomial: ; constants vanish.
- A central difference is a cheap, accurate check of any derivative you compute by hand. Deep-learning practitioners use exactly this "gradient check" to test backpropagation code.
- Read inputs token by token, not line by line, when the statement and the sample disagree on layout.