Card Game
Time limit1sMemory limit128 MB
Two players alternately pick cards and OR the value into a shared number, losing by completing 511 or moving with no cards left.
- Level
Medium7 of 10
- Topics
- Game theory, Bit manipulation
- Solved
- No attempts yet
Problem
Myungwoo and Hongjun are playing a card game. They use cards, each showing a number from 0 to 511, and one sheet of paper. At the start the paper has 0 written on it.
Myungwoo goes first and the two take turns. On your turn you freely pick one of the remaining cards. If the picked card shows and the paper shows , erase the number on the paper and write the bitwise OR of the two numbers, . You lose the game if your turn starts with no cards left, or if the number you just wrote is 511.
Both players know the optimal strategy for this game and play it. Given the cards, decide who wins.
Input
The first line has the initial number of cards ().
The second line has non-negative integers separated by spaces, the numbers written on the cards. Each number written on a card is smaller than 512.
Output
Print myungwoo if Myungwoo wins, or hongjun if Hongjun wins.
Hint
If the paper shows 510 and every remaining card is odd, the player to move writes 511 whichever card they pick, so that player loses.