codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1407C.md (2157B)


      1 Source: https://codeforces.com/problemset/problem/1407/C
      2 
      3 C. Chocolate Bunny
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 This is an interactive problem.
     22 
     23 We hid from you a permutation $p$ of length $n$, consisting of the elements from $1$ to $n$. You want to guess it. To do that, you can give us 2 different indices $i$ and $j$, and we will reply with $p_{i} \bmod p_{j}$ (remainder of division $p_{i}$ by $p_{j}$).
     24 
     25 We have enough patience to answer at most $2 \cdot n$ queries, so you should fit in this constraint. Can you do it?
     26 
     27 As a reminder, a permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array) and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).
     28 
     29 Input
     30 
     31 The only line of the input contains a single integer $n$ ($1 \le n \le 10^4$) — length of the permutation.
     32 
     33 Interaction
     34 
     35 The interaction starts with reading $n$.
     36 
     37 Then you are allowed to make at most $2 \cdot n$ queries in the following way:
     38 
     39 * "? x y" ($1 \le x, y \le n, x \ne y$).
     40 
     41 After each one, you should read an integer $k$, that equals $p_x \bmod p_y$.
     42 
     43 When you have guessed the permutation, print a single line "! " (without quotes), followed by array $p$ and quit.
     44 
     45 After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
     46 
     47 * fflush(stdout) or cout.flush() in C++;
     48 * System.out.flush() in Java;
     49 * flush(output) in Pascal;
     50 * stdout.flush() in Python;
     51 * see documentation for other languages.
     52 
     53 Exit immediately after receiving "-1" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.
     54 
     55 Hack format
     56 
     57 In the first line output $n$ ($1 \le n \le 10^4$). In the second line print the permutation of $n$ integers $p_1, p_2, \ldots, p_n$.
     58 
     59 Example
     60 
     61 Input
     62 
     63 ```
     64 3
     65 
     66 1
     67 
     68 2
     69 
     70 1
     71 
     72 0
     73 ```
     74 
     75 Output
     76 
     77 ```
     78 ? 1 2
     79 
     80 ? 3 2
     81 
     82 ? 1 3
     83 
     84 ? 2 1
     85 
     86 ! 1 3 2
     87 ```