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

OrBiTal (hard)

Back to problem

Editorial

Let S=∑i=1NAiS=\sum_{i=1}^{N}A_iS=∑i=1N​Ai​. One strength-KKK particle adds K2K^2K2 in total, so only strengths satisfying K2∣SK^2\mid SK2∣S are candidates.

Let XiX_iXi​ be the particle count at orbital iii, with indices cycling through 1,…,N1,\ldots,N1,…,N. Compute Ci=Ai−1−2Ai+. Then . Split the indices into cycles of length . Integrate once, determine the initial slope from the cyclic condition, and integrate again. Every cycle permits adding an arbitrary integer constant to its base solution.

Let BBB be the sum of the base solutions and let LLL be the sum of their negated minima. The required particle count is P=S/K2P=S/K^2P=S/K2. The candidate is valid exactly when m∣(P−B)m\mid(P-B)m and .

With DDD candidate strengths, the time complexity is O(ND+N)O(ND+N)O(ND+N) and the space complexity is O(N)O(N)O(N).

Proof

The second difference of the triangular kernel leaves −2-2−2 at its center and 111 at both positions KKK steps away. On a cycle, writing pt=yt−yt−1p_t=y_t-y_{t-1}pt​ gives . The slopes close exactly when , and uniquely fixes the initial slope. A nonintegral initial slope is impossible.

In subtask 1, a nonzero particle has peak K≤max⁡Ai≤3K\leq\max A_i\leq3K≤maxAi​≤3, leaving only three strengths.

For subtask 2, let ddd be the common difference. If d=0d=0d=, check . If , we must have . Let , . The base-solution sum is and the minimum nonnegative total is . Thus check and , taking per candidate.

Ai+1C_i=A_{i-1}-2A_i+A_{i+1}
Ci​=Ai−1​−2Ai​+Ai+1​
Ci=Xi−K−2Xi+Xi+KC_i=X_{i-K}-2X_i+X_{i+K}Ci​=Xi−K​−2Xi​+Xi+K​
g=gcd⁡(N,K)g=\gcd(N,K)g=gcd(N,K)
m=N/gm=N/gm=N/g
∣
(P−
B)
(P−B)/m≥L(P-B)/m\geq L(P−B)/m≥L
=
yt​−
yt−1​
pt+1−pt=ctp_{t+1}-p_t=c_tpt+1​−pt​=ct​
∑ct=0\sum c_t=0∑ct​=0
∑pt=0\sum p_t=0∑pt​=0

After the second integration, all integer solutions differ by a constant on each cycle. This constant is at least the negated minimum and changes the particle count by a multiple of mmm. The stated divisibility and lower-bound conditions are therefore necessary and sufficient. The constructed intensity sequence and AAA have equal second differences and equal sums. A circular sequence with zero second difference is constant, so the two sequences agree.

For an arithmetic progression with d≠0d\ne0d=0, only C1=NdC_1=NdC1​=Nd and CN=−NdC_N=-NdCN​=−Nd are nonzero. They must belong to the same cycle, since each cycle has curvature sum zero, so gcd⁡(N,K)=1\gcd(N,K)=1gcd(N,K)=1. Starting at position 111 and repeatedly adding KKK, position NNN occurs after r≡−K−1(modN)r\equiv-K^{-1}\pmod Nr≡−K−1(modN) steps. The base solution consists of two linear pieces with height h=dr(N−r)h=dr(N-r)h=dr(N−r), total B=Nh/2B=Nh/2B=Nh/2, and minimum min⁡(0,h)\min(0,h)min(0,h). Its minimum nonnegative total is therefore ∣B∣|B|∣B∣, and constants change its total by multiples of NNN. When d=0d=0d=0, every cycle has zero base solution; the condition is m∣Pm\mid Pm∣P, equivalently K2∣gcd⁡(N,K)A1K^2\mid\gcd(N,K)A_1K2∣gcd(N,K)A1​.

0
K2∣gcd⁡(N,K)A1K^2\mid\gcd(N,K)A_1K2∣gcd(N,K)A1​
d≠0d\ne0d=0
gcd⁡(N,K)=1\gcd(N,K)=1gcd(N,K)=1
r≡−K−1(modN)r\equiv-K^{-1}\pmod Nr≡−K−1(modN)
1≤r<N1\leq r<N1≤r<N
B=dNr(N−r)/2B=dNr(N-r)/2B=dNr(N−r)/2
∣B∣|B|∣B∣
P≥∣B∣P\geq|B|P≥∣B∣
P≡B(modN)P\equiv B\pmod NP≡B(modN)
O(log⁡N)O(\log N)O(logN)

Solution written by GPT6