Good evening Codeforces, let me briefly describe solutions for all problems of today's morning yandex algorithm round. Thanks everyone who participated, I apologize for making problems a bit too tough and viscous for a 100 minutes contest. Anyway, I hope everyone found something interesting.
I would like to thank lperovskaya for organising this competition and managing Yandex.contest, snarknews and SergeiFedorov for their help with the problemset, Endagorion, PavelKunyavskiy, AleX, glebushka98, gustokashin, map and boris for testing. Special thanks to Gassa and my girlfriend Marina Kruglikova for fixing mistakes and disambiguations in English and Russian statements.
Let's get it started.
Problem A. Odysseus Sails Home.
There is no tricky idea behind this problem: one just needs to check if the vector (xf - xs, yf - ys) can be represented as a convex combination of vectors (xi, yi). One of the easiest approaches for the general case is to try all pairs of wind vectors and check if the target vector lies inside the cone they form. However, the devil is in the details. One shouldn't forget to:
Check if it's possible to get to Ithaca using only one wind direction;
Special if for case (xf, yf) = (xs, ys);
Ignore wind vectors (xi, yi) = (0, 0);
Avoid usage of doubles — everything fits in long long.
Problem B. Chariot Racing.
For the fixed value t = const we can easily calculate the intersection of all segments (chariots) as max(0, min(bi + vi * t) - max(ai + vi * t)). The problem was to find maximum for t ≥ 0.
Both min(bi + vi * t) and max(ai + vi * t) are convex functions. min(bi + vi * t) is concave upward, because it's derivative only decreases, as faster chariots overtake slower one. Similar max(ai + vi * t) is convex down. This means function min(bi + vi * t) - max(ai + vi * t) is concave upward, and this, in turn is sufficient condition for applying ternary search.
Ternary search was enough to solve the problem, but the solution which does binary search on derivative is faster and more stable to precision. We need to find the maximum t such that the leading chari
Problem C. Equality and Roads.
Problem D. Sequences of Triangles.
Thanks to snarknews — the author and developer of this problem.
Problem E. Strong Squad.
Thanks to SergeiFedorov — the author of this problem.