Our approaches are often complementary. I'm not ready to say that I abhor calculus, but I am old (and tired) enough to call in transferable concepts where they apply if it avoids re-deriving a result. But, this afternoon I did the whole d/dx on this problem, but surrendered when I saw x4 and x3 terms. So I didn't derive x=40 that way, I got it numerically from my Newton-Raphson program, then plugged 40 into the stationary condition just to verify the approaches agree.
I worked in optics long enough for Snell's law to have been like f = ma to me. It just shows the bend in light's path at interfaces that creates the least time path. Just as OP asks here. In optics it's refractive indices, in this puzzle it's running vs swimming, but it's the same effect. But my optics journey was 40 years ago and the connection didn't hit me at first. Full disclosure, Snell's law is an extension of the principle of least action, a fundamental underpinning in several disciplines.
Long version of the answer to a question that wasn't asked...