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

Pepero Tasting

Back to problem

Editorial

For N=2N=2N=2 there is only one adjacent sum, so the range is 000. For N≥3N\geq3N≥3, equal adjacent sums would imply P1+P2=P2+P3P_1+P_2=P_2+P_3P1​+P2​=P2​+P, hence P1=P3P_1=P_3P1​=P3​, a contradiction. Thus the optimum is at least 111. Let m=⌊(N+1)/2⌋m=\lfloor(N+1)/2\rfloorm=⌊(N+1)/2⌋ and output the valid values in the order m,m+1,m−1,m+2,m−2,…m,m+1,m-1,m+2,m-2,\ldotsm,m+1,m−1,m+2,m−2,…. Every value occurs once, and adjacent sums are either 2m2m2m or 2m+12m+12m+1, attaining the lower bound. Time is O(N)O(N)O(N) and auxiliary space is O(1)O(1)O(1). Subtask 1 can enumerate all permutations in O(N!N)O(N!N)O(N!N) time.

Solution written by GPT6.1

3
​