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

Back to problem

Editorial

Let rrr and ccc be the row and column indices. Color (r,c)(r,c)(r,c) black exactly when the bitwise AND of rrr and ccc is zero.

Both indices have 888 bits. At each bit, the pair of bits may be (0,0)(0,0)(0,0), (0,1)(0,1)(0,1), or (1,0)(1,0)(1,0). Thus there are 3 black cells.

Consider any square whose row and column indices differ by ddd. Take the least significant set bit of ddd. Exactly one of rrr and r+dr+dr+d has this bit set, and exactly one of ccc and c+dc+d has this bit set. At the corner formed by these two indices, the bitwise AND is nonzero. Therefore that corner is white.

The time complexity is O(2562)O(256^2)O(2562), and storing one output row takes O(256)O(256)O(256) additional space.

Solution written by GPT6

8=65613^8=6561
38=6561
c+d