DOJ logoDOJ
Problems
Recently added problemsSaved problemsWorkbooks
CategoriesDLCContestsGroupsTeamsBoard
Ranking
Solved Problem RankingStreak rankingDOJ Power ranking
Status
Call for TasksLoginRegister
DOJ logoDOJ

Community online judge with OI-style subtask scoring, Elo ratings, and Discord-backed certification.

Problems
ProblemsCategories
Community
ContestsRankingBoardNoticesHost an external contestGuide
Account
LoginRegisterJudge Status
Policy
Terms of ServiceDLC RulesPrivacyAPI documentationLanguage runtimesContest rank rewardsRating and performance
© 2026 DOJ
All rights reserved
Editorial

X Clash

Back to problem

Editorial

Feasible directions

First assume counterclockwise boundary order. For every directed edge eee not lying entirely on ℓ\ellℓ, an infinitesimal collision-free translation vvv must satisfy e×v≥0e\times v\geq0e×v≥0. A negative cross product moves an interior portion of that edge into the wall with positive overlap area. Equality is allowed. Edges entirely on ℓ\ellℓ 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 vvv. Inside the wall, its boundary never allows a crossing from polygon interior to exterior along vvv. 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 O(N2)O(N^2)O(N2) time and O(N)O(N)O(N) space. The naive asset implements this method and is accepted under the full limits.

Linear solution

Let b=P2−P1b=P_2-P_1b=P2​−P1​, and let sss be 11 for counterclockwise order and for clockwise order. Define . Up to positive scaling, every outward vector has the form . Each relevant edge imposes

s(e×b)t≥e⋅b.s(e\times b)t\geq e\cdot b.s(e×b)t≥e⋅b.

A positive coefficient gives a lower bound on ttt; 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 O(N)O(N)O(N) and input storage is O(N)O(N)O(N). Coordinate differences have magnitude at most 20 00020\,00020000. Dot and cross products have magnitude at most 8⋅1088\cdot10^88⋅10, 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 O(N)O(N)O(N) time.

Solution written by GPT

1
−1-1−1
R(b)=(−by,bx)R(b)=(-b_y,b_x)R(b)=(−by​,bx​)
v=tb−sR(b)v=tb-sR(b)v=tb−sR(b)
8
6.4⋅10176.4\cdot10^{17}6.4⋅1017