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

Watermelon Game

Back to problem

Editorial

Count each size and process sizes increasingly: add ⌊cx/2⌋\lfloor c_x/2\rfloor⌊cx​/2⌋ to cx+1c_{x+1}cx+1​ and replace cxc_xcx​ by its parity. The number reaching size xxx is bounded by its initial count plus the pairs reaching size x−1x-1x−1; this process attains that bound inductively. The greatest remaining size is optimal. A positive count can become zero, but then a larger fruit is created, preserving the global maximum. The largest possible size is N+⌊log⁡2N⌋≤200017N+\lfloor\log_2N\rfloor\leq200017N+⌊log2​N⌋≤200017. Time and space are O(N)O(N)O(N). For the small subtask, search every merge from sorted lists; the number of states is at most the number of set partitions, at most 4140 for N≤8N\leq8N≤8.

Solution written by GPT6