I don’t know why you would assume that ballX and playerX are always ordered the same way but I interverted ballX and playerX in testcase 2 so there should be no surprise now.
Thanks, inverting them is fine, but dropping it as a surprise during validation is not. Those who don’t have access to the contribution won’t understand what’s going on.
LOL - after seeing brute-force is not viable because of the huge range of possibe solutions, I tried to solve this on paper with calculus but failed miserably when the equation became of degree 4… Then my thoughts were around gradient descent and I started to feel dispair.
But in the end it turned out that this is much simpler than that, as f() has no other local minimums.
Using so much zoom last year should have given the idea earlier…
If you consider T(x) the time spent to reach the ball depending on the x you choose, then the derivative T’ is not too hard to calculate.
And then whatever formula you get, even if you have squareroots, powers etc, you just have to find its zero so even if you cannot solve the equation for exact value, any method that gives a good approximation of a zero would be fine (dichotomy, newton, etc).
I am not sure about that, x range in the last test case is 20M integers.
Sure, but then it is no longer the analytic solution on paper I originally aimed for…
Anyhow, a simple ‘zoom-in’ type of search is simpler than any newton and also works here as the time() seems to be monotone decreasing to the global minimum, then monotone increasing.
My post was meant more about the thought process than about the solution.
after dart 2.12 there is null protection. But code is still for old version of dart.
List? inputs;
inputs = stdin.readLineSync()!.split(’ ‘);
int STARTX = int.parse(inputs[0]);
int STARTY = int.parse(inputs[1]);
int BEACHY = int.parse(stdin.readLineSync()!);
inputs = stdin.readLineSync()!.split(’ ');
int BALLX = int.parse(inputs[0]);
int BALLY = int.parse(inputs[1]);
int SPEEDLAND = int.parse(stdin.readLineSync()!);
int SPEEDWATER = int.parse(stdin.readLineSync()!);
Do you mean the default code works, but should be updated? Also, is it more of a general issue instead of an issue on this particular puzzle? If so, I would suggest you to open a new topic to raise the issue. Thank you.