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 account linking.

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

Net Fishing

Back to problem

Editorial

Measure a clockwise gap in steps between consecutive numbered points. For a set of selected points, consider the gaps between consecutive selected points in clockwise order, including the gap from the last point back to the first.

The final convex polygon contains the center if and only if every gap is at most NNN. A gap of exactly NNN corresponds to a diameter, so it may place the center on the boundary.

Let ddd be the largest gap between the M−1M-1M−1 given points. These gaps are

Ai+1−Ai(1≤i<M−1),A1+2N−AM−1.A_{i+1}-A_i\quad(1\leq i<M-1),\qquad A_1+2N-A_{M-1}.Ai+1​−Ai​(1≤

If d≤Nd\leq Nd≤N, choosing any unoccupied point merely splits one existing gap into two smaller gaps. Every unoccupied point works, so the answer is 2N−M+12N-M+12N−M+1.

If d>Nd>Nd>N, this gap must be split. Since the gaps sum to 2N2N2N, there is only one gap greater than NNN. Choose a point xxx steps clockwise from its starting point. The two new gaps are xxx and d, both of which must be at most . Equivalently,

d−N≤x≤N.d-N\leq x\leq N.d−N≤x≤N.

The answer is therefore 2N−d+12N-d+12N−d+1.

The input is already sorted, so no sorting is needed. Read the points while keeping only the first point, the previous point, and the largest gap so far. Finally, check the wraparound gap. The time complexity is O(M)O(M)O(M) and the additional space complexity is O(1)O(1)O(1).

Proof

Consider an edge joining consecutive vertices of the final polygon in clockwise order. If their clockwise gap is ggg, the corresponding central angle is 2πg/(2N)2\pi g/(2N)2πg/(2N).

The interior of a clockwise convex polygon is to the right of each directed edge. The center is to the right of this edge when the central angle is less than π\piπ, on the edge when it equals π\piπ, and to the left when it is greater than . Thus, the center belongs to the closed interior half-plane of this edge exactly when . A convex polygon is the intersection of the closed interior half-planes of all its edges. Therefore, it contains the center exactly when every gap is at most .

Solution written by GPT6

i<
M−
1),A1​+
2N−
AM−1​.
−xd-x
d−x
NNN
π\pi
π
g≤Ng\leq Ng≤N
NNN

Now consider the gaps between the given points. If they are all at most NNN, adding any unoccupied point preserves this property, so every unoccupied point is valid.

If a gap exceeds NNN, adding a point elsewhere leaves that gap unchanged and cannot produce a valid polygon. Since all gaps sum to 2N2N2N, there is at most one such gap, and all other gaps already satisfy the condition. Consequently, splitting the large gap into xxx and d−xd-xd−x is valid if and only if both new gaps are at most NNN.

The valid values of xxx are the integers from d−Nd-Nd−N through NNN. Since d>Nd>Nd>N, every such point is strictly between the two endpoints of the large gap. These endpoints are consecutive given points, so all points inside the gap are unoccupied. The number of valid choices is therefore exactly N−(d−N)+1=2N−d+1N-(d-N)+1=2N-d+1N−(d−N)+1=2N−d+1.