Monochrome Medicine
Dr Tony Zamboni is a renowned physician, especially well-versed in microbiology. However, due to some unfortunate events during his experiments, Dr Zamboni has lost his hearing and voice, and his vision has been reduced to monochromacy: he can distinguish only two colours.
Prior to the accident, Dr Zamboni was working on a miracle medicine. He was sequencing molecules, labelled
through
, and was testing different permutations in an attempt to create a vaccine that would allow programmers to properly read every problem statement on their first try, and never encounter issues such as integer overflow.
Just before his machine exploded, he discovered the correct permutation!
Dr Zamboni knows this permutation (i.e. a particular arrangement of the unique values
through
), but you do not.
Due to his condition, you can communicate with him only in the following way:
For each query, you assign each molecule either black or white. In other words, for every molecule , you choose a colour
.
Dr Zamboni then rearranges the molecules in the order of his hidden permutation and clicks his tongue once for every pair of consecutive molecules whose assigned colours are different.
Thus, for a query , his response is
\[
\left\lvert \left\lbrace i \mid 1 \le i < n,\ b_{P_i} \ne b_{P_{i+1}} \right\rbrace \right\rvert.
\]
Using only these queries, determine the hidden permutation before Dr Zamboni falls asleep.
Interaction
This is an interactive problem. Your submission will be run against an interactor, which reads from the standard output of your program and writes to its standard input. The interaction must follow the format below:
The interactor first sends one integer
, the number of molecules in the vaccine.
You may present Dr Zamboni with up to queries to determine information about the true molecular permutation before he falls asleep. To conduct a query, print a line in the form
. Each
should be either
or
, and represents the colour you assign the
th molecule. The interactor will respond with a single integer, representing the number of adjacent pairs that have different colours when your molecules are arranged in the order of Dr Zamboni's permutation.
Once you have determined the true molecular permutation of the vaccine, print a line in the form ,
space-separated values, where each value
to
appears uniquely. Note that this interaction cannot distinguish between a permutation and its reverse, so either orientation will be accepted.
You will receive a Wrong Answer if:
- You conduct more than
queries, as Dr Zamboni will fall asleep, or
- You send data that is invalid, or
- Your final answer is wrong.
After printing each line, you must flush stdout. Failure to do so may result in an Idleness Limit Exceeded verdict.
For C++, you may use
cout << endlto output, or callcout.flush()after each output.For Python, use
flush=Trueinprint(), or callsys.stdout.flush()after each output.
Example
Interaction 1
5
? 00000
0
? 10000
1
? 11000
3
? 10101
2
? 00010
2
! 1 4 2 5 3
The secret permutation in this example is .
One way to view each query is as assigning a binary value to each molecule . Dr Zamboni then reads these values in the order of the secret permutation and returns the number of times the value changes between consecutive positions.
For example, with secret permutation , the query
10101 becomes 10011. This sequence changes colour twice, so the response is . Using this approach, we will analyse each query as follows:
? 00000→00000: no colour changes, so the response is.
? 10000→10000: one colour change, so the response is.
? 11000→10100: three colour changes, so the response is.
? 10101→10011: two colour changes, so the response is.
? 00010→01000: two colour changes, so the response is.
Comments