DOJ logoDOJ
Problems
Recently added problemsSaved problems
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-backed certification.

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

귀가 장치

Back to problem

Editorial

The bitwise OR operation cannot turn a bit that has become 1 back to 0. Therefore, any bit that is already 1 in AAA must also be 1 in BBB. That is, (A∣B)=B(A \mid B) = B(A∣B)=B is required. Also, if pressing a certain button iii includes a bit in aia_iai​ that is not in BBB, that bit will be turned on, and it can never become BBB ultimately. Therefore, the only usable buttons are those satisfying (ai∣B)=B(a_i \mid B) = B(ai​∣B)=B. Now, we need to turn on each bit that is 1 in BBB but 0 in AAA. For each bit, if there is at least one button that includes that bit and satisfies (ai∣B)=B(a_i \mid B) = B(ai​∣B)=B, we just need to press that button. Since the range of integers is up to 10910^9109, there are only 30 bits to check. By looking at each button and saving one button that can turn on each bit, it can be solved in O(Nlog⁡109)O(N \log 10^9)O(Nlog109). The number of selected buttons is less than or equal to the number of required bits, which is at most 30, so it always satisfies the 100 times limit.