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

Murimuri Sequence

Back to problem

Editorial

The equation ax2+bx+c=0ax^2+bx+c=0ax2+bx+c=0 has a real root whenever its discriminant b2−4acb^2-4acb2−4ac is nonnegative. In particular, this is always true when ac≤0ac\leq0ac≤0.

We therefore arrange the sequence so that values two positions apart have opposite signs. Use the following sign pattern:

0,+,−,−,+,+,−,−,+,+,…0,+,-,-,+,+,-,-,+,+,\ldots0,+,−,−,+,+,−,−,+,+,…

After the initial zero, the length-444 pattern +,−,−,++,-,-,++,−,−,+ repeats. Two positions apart in this pattern always have opposite signs, while a pair involving the first value has product zero.

Among the remaining 2N2N2N positions, exactly NNN are positive and NNN are negative. Put 1,2,…,N1,2,\ldots,N1,2,…,N into the positive positions and −1,−2,…,− into the negative positions. Thus every integer from to is used exactly once.

For any three consecutive values a,b,ca,b,ca,b,c, the construction gives ac≤0ac\leq0ac≤0. Hence

b2−4ac≥b2≥0,b^2-4ac\geq b^2\geq0,b2−4ac≥b2≥0,

so every required equation has at least one real root.

The time complexity is O(N)O(N)O(N), equal to the output size, and the additional space complexity is O(1)O(1)O(1).

Solution written by GPT6

N-1,-2,\ldots,-N
−1,−2,…,−N
−N-N−N
NNN