mit-indiv09-carldant
Credit where credit is due: this problem comes from the 2004 finals in Prague, where one of your coaches failed to solve it. Surely you can do better! We’ve modified the problem statement to clarify that the endpoints are not repeated, that Carl never revisits the origin, and to have only one test case per run.
Ants leave small chemical trails on the ground in order to mark paths for other ants to follow. Ordinarily these trails follow rather straight lines. But in one ant colony there is an ant named Carl, and Carl is not an ordinary ant. Carl will often zigzag for no apparent reason, sometimes crossing his own path numerous times in the process. When other ants come to an intersection, they always follow the path with the strongest scent, which is the most recent path that leads away from the intersection point.
Ants are 1 centimeter long, move and burrow at 1 centimeter per second, and follow their paths exactly (bending at right angles when moving around corners). Ants cannot cross or overlap each other. If two ants meet at the exact same instant at an intersection point, the one that has been on Carl’s path the longest has the right of way; otherwise, the ant that has been waiting the longest at an intersection will move first.
Carl burrows up from the ground to start at the origin at time 0. He then walks his path and burrows back down into the ground at the endpoint. The rest of the ants follow at regular intervals. Given the description of Carl’s path and when the other ants start the path, you are to determine how long it takes the entire set of ants to finish burrowing back into the ground. All the ants are guaranteed to finish.
For simplicity, Carl always travels on line segments parallel to the axes, and no endpoints lie on any segment other than the ones which they serve as an endpoint. No endpoint occurs more than once, and Carl never revisits the origin (0, 0).
Carl finished the path at time t1
The ants finished in the following order:
a1 a2 a3 ... am
The last ant finished the path at time t2Here, a1, a2, a3, . . ., am are the ant numbers in the order that they go back underground, and t1 and t2 are the times (in seconds) at which Carl and the last ant finish going underground.
4 7 4
0 4
2 4
2 2
-2 2Output:
Carl finished the path at time 13
The ants finished in the following order:
0 2 1 3 4 5 6
The last ant finished the path at time 294 7 2
0 4
2 4
2 2
-2 2Output:
Carl finished the path at time 13
The ants finished in the following order:
0 4 1 5 2 6 3
The last ant finished the path at time 19Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.