And Password

View as PDF

Submit solution

Points: 20 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

Andrew has a special computer that contains some very special content. He also has an appropriately special way of unlocking his computer. To get in, he needs a password P of length 3 \le N \le 2048 that is a permutation of the numbers 1, 2, \dots, N. Unfortunately, N numbers can be a lot to remember. In order to help him in case he forgets, Andrew's computer returns him special hints. He can enter two integers i and j (1 \le i, j \le N, i \ne j) and his computer will tell him the bitwise AND value of P_i and P_j (P_i \mathbin{\&} P_j). Andrew figures that no one would be able to guess his password given so little information and just to be extra safe, he sets his computer to only give up to 5120 hints.

Are you able to get into Andrew's computer?

Interaction

This is an interactive problem. In the first line, you will receive the integer N, the length of Andrew's password.

Now, you may ask for hints from the computer. To ask for a hint, print ? i j to ask for the bitwise AND value of P_i and P_j (P_i \mathbin{\&} P_j).

The judge will respond with the answer, or -1 if your output was invalid or if you exceeded the hint limit. Exit immediately after receiving -1 or else you will receive an arbitrary verdict.

To guess the password, print ! P_1, P_2, ... P_n and terminate your program. Note that guessing does not count as one of the 5120 hints.

Note: This interactor is not adaptive, i.e. P is fixed at the start of each test case.

Subtask 1 [30%]

3 \le N \le 20

Subtask 2 [30%]

N is 1 less than a power of 2 (e.g. 3, 7, 15, \dots) and 3 \le N \le 2048.

Subtask 3 [40%]

3 \le N \le 2048

Sample Interaction

>>> denotes your output; don't actually print this out.

3
>>> ? 1 2
0
>>> ? 1 3
2
>>> ? 2 3
1
>>> ! 2 1 3

Explanation for Sample Interaction

The answer is 2 1 3. The first hint asks for P_1 \mathbin{\&} P_2 = 2 \mathbin{\&} 1 = 0. The second hint asks for P_1 \mathbin{\&} P_3 = 2 \mathbin{\&} 3 = 2. The third hint asks for P_2 \mathbin{\&} P_3 = 1 \mathbin{\&} 3 = 1.


Comments

There are no comments at the moment.