Feasible directions
First assume counterclockwise boundary order. For every directed edge not lying entirely on , an infinitesimal collision-free translation must satisfy . A negative cross product moves an interior portion of that edge into the wall with positive overlap area. Equality is allowed. Edges entirely on impose no such condition.
These inequalities, together with an outward direction, are sufficient for a straight-line escape. Intersect the polygon with a line parallel to . Inside the wall, its boundary never allows a crossing from polygon interior to exterior along . Hence each nonempty interior section continues as one interval to the opening. Translating this interval outward cannot enter the wall. Sections through vertices follow by a limiting argument.
They are also necessary for any continuous escape path: take a sufficiently small nonzero displacement along that path. Every non-opening edge imposes its local inequality. All opening edges point in the same direction. Since all edge vectors sum to zero, these inequalities force a nonzero feasible vector to point outward. A tangent vector would have zero cross product with every edge, contradicting positive area. Thus changing direction during the motion does not help.
Quadratic solution
The boundary of the feasible angular interval is parallel to a polygon edge. Test both directions of every edge, requiring an outward direction and every edge inequality. Positive area rules out a nonzero feasible direction tangent to the opening. Therefore, if any direction works, one of these candidates works. This takes time and space. The naive asset implements this method and is accepted under the full limits.
Linear solution
Let , and let be for counterclockwise order and for clockwise order. Define . Up to positive scaling, every outward vector has the form . Each relevant edge imposes
A positive coefficient gives a lower bound on ; a negative one gives an upper bound. A zero coefficient with a positive right-hand side makes the answer impossible. Otherwise, the answer is possible exactly when the final lower bound does not exceed the upper bound. Equality must be accepted.
Store rational bounds with positive denominators and compare by cross multiplication. Time is and input storage is . Coordinate differences have magnitude at most . Dot and cross products have magnitude at most , and each product used for a rational comparison is at most in magnitude. Signed 64-bit arithmetic suffices.
Subtask 1 contains triangles. Translate the opposite vertex toward an interior point of the opening; every triangle can be removed. Including input reading, this takes time.
Solution written by GPT