#P17038. [NWERC 2021] Boredom Buster
[NWERC 2021] Boredom Buster
Problem Description
You are stuck alone in a cabin and it is raining outside. You are bored out of your mind and the only available boredom buster is a deck of Memory cards. Playing Memory by yourself is not very fun, but you developed a single player variant that requires not only good memory but also strategy.
It goes like this: You have a shuffled deck of cards, where is even and each card contains a number from to . There are exactly two cards of each number. The cards are laid face down on the table and your goal is to find what number is written on each of them.
In one move, you pick up two cards. Before revealing them, you randomly shuffle them so that you do not know which card was where. Then you look at the two cards. After that, you shuffle them again face down before you put them back where they were. That way, you know the numbers of the two cards and where they are, but not which card ended up where, or even what card came from which spot initially.
Your task is to write a program that will beat this game.
Interaction
This is an interactive problem. Your submission will be run against an interactor, which reads the standard output of your submission and writes to the standard input of your submission. This interaction needs to follow a specific protocol:
- The interactor first sends an integer (, is even). The only time is not equal to is in the sample.
- Your submission then repeatedly sends two integers and (, ) preceded by
?. - The interactor replies with two integers and (), indicating that after the query either the th card is and the th card is , or the th card is and the th card is .
- When you are ready to print the answer, print
!followed by integers , where is the number of the th card at the time of writing.
You may use at most moves. Printing the answer does not count as a move.
The interactor is not adaptive. Initial positions of the cards are determined by the interactor before any interaction takes place. When you make a move the two cards will be shuffled uniformly randomly by the interactor both before being shown to you and before being placed back down. The initial layout of the cards is guaranteed to be a random permutation of .
Your submission will be run on exactly test cases, each of which will have .
Make sure you flush the buffer after each write. A testing tool is provided to help you develop your solution.
Interaction Sample #1
In this sample, Sample Input contains the messages sent by the interactor to the submission, and Sample Output contains the messages sent by the submission to the interactor. They occur alternately in the order shown by the original interaction transcript.
6
3 2
2 3
1 1
3 3
? 2 1
? 5 3
? 6 4
? 1 3
! 3 2 3 1 2 1