No.3400 Nana's Plus Permutation Game (7 + 7) ÷ 7
Story
Let's play the permutation guessing game again. The strategy from last time has been found out.By the way, how on earth are you supposed to handle dddd k d k d k dddd k d k d k dddd k dddd k ddkddkddkk and ddkddkddkk d k d k d kdkdkdk?
Problem Statement
There is a permutation $P = (P_1, P_2, \cdots,P_{N})$ of $(1, 2, \cdots, N)$ with $N$ elements. $N$ is a prime number. You are given $N$, but $P$ is not given and is kept hidden by the judge.
You can send the following query to the judge.
・Choose integers $i, j (i \neq j)$ between $1$ and $N$, inclusive. If there exists an integer $k$ such that $P_i + P_j = P_k$, you are given $k$; otherwise, you are given $-1$.
You can use this query up to $3N$ times. Find $P$.
Solve $T$ test cases.
Constraints
・$1 \leq T$・$5 \leq N$
・$N$ is a prime number
・$P$ is a permutation of $(1, 2, \cdots, N)$
・$P$ is determined before the interaction and is fixed
・All inputs are integers
・The sum of $N$ over the test cases is at most $10001$
Input and Output
First, $T$ is given by the judge. After this, the following interaction is performed $T$ times.
$T$
First, at the beginning of each interaction, $N$ is given.
$N$
After that, you can send queries in the following format up to $3N$ times. They must satisfy $1 \leq i, j \leq N, i \neq j$.
$1$ $i$ $j$
The judge responds with the answer to the query. If there exists an integer $k$ such that $P_i + P_j = P_k$, $k$ is given; otherwise, $-1$ is given.
$k$
When outputting your answer, print it as follows. If this is the $T$-th time, terminate your program immediately.
$2$ $P_1$ $P_2$ $\cdots$ $P_N$
Notes
・After each output, print a trailing newline and flush the output.・The judge's behavior for invalid output or actions may be undefined.
Sample
The following is one example.| Program's output | Judge's output | Explanation |
|---|---|---|
1 | First, $T$ is given. | |
5 | First, $N$ is given. At this point, the judge is hiding $P =(1, 3, 4, 5, 2)$. | |
1 1 3 | The query $i = 1, j = 3$ is sent to the judge. | |
4 | Since $P_1 + P_3 = 5 = P_4$, $4$ is given. | |
1 2 3 | The query $i = 2, j = 3$ is sent to the judge. | |
-1 | Since $P_2 + P_3 = 7 > 5$, $-1$ is given. | |
2 1 4 2 3 5 | The permutation $(1, 4, 2, 3, 5)$ is output as the answer. This does not match $P$, so the answer is judged incorrect. |
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。