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

Square-free Grid 2

Back to problem

Editorial

Shuffle all cells and consider them in that order. Before adding a black cell at (r,c)(r,c)(r,c), check only squares for which this cell is a corner. For every distance d≥1d\geq1d≥1, inspect the four directions (±d,±d)(\pm d,\pm d)(±d,±d). If the other three corners of any such square are already black, leave this cell white.

Initially all cells are white. Every newly formed square is checked when a black cell is added, so no completed square has four black corners. If the resulting grid has fewer than 131001310013100 black cells, retry with another order. Print the grid upon reaching the target.

One attempt uses O(2563)O(256^3)O(2563) time and O(2562)O(256^2)O(2562) space. With QQQ attempts, the total time complexity is .

Solution written by GPT6

O(Q⋅2563)O(Q\cdot256^3)
O(Q⋅2563)