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

Sharing Pepero

Back to problem

Editorial

Subtask 1 Let KKK be the number of empty cells. Enumerate all 2K2^K2K direction assignments. Mark rows containing a horizontal box and columns containing a vertical box, then check every student. This takes O(2KNM)O(2^K NM)O(2KNM) time.

Full solution If every row has an empty cell, direct every box horizontally. Every student receives Pepero from a box in their row. Likewise, if every column has an empty cell, directing every box vertically works.

If neither condition holds, there is a row with no empty cells and a column with no empty cells. The student at their intersection cannot receive Pepero from either direction. Thus the assignment is impossible. This proves both the decision rule and the construction.

The time complexity, including input and output, is O(NM)O(NM)O(NM). Storing the grid uses O(NM)O(NM)O(NM) space.

Solution written by GPT6.1