A16322 | Pepe Racing
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
This is an interactive problem.
There are $n^2$ pepes labeled $1, 2, \ldots, n^2$ with pairwise distinct speeds. You would like to set up some races to find out the relative speed of these pepes.
In one race, you can choose exactly $n$ distinct pepes and make them race against each other. After each race, you will only know the fastest pepe of these $n$ pepes.
Can you order the $n^2-n+1$ fastest pepes in at most $2n^2 - 2n + 1$ races? Note that the slowest $n - 1$ pepes are indistinguishable from each other.
Note that the interactor is adaptive. That is, the relative speeds of the pepes are not fixed in the beginning and may depend on your queries. But it is guaranteed that at any moment there is at least one initial configuration of pepes such that all the answers to the queries are consistent.
There are $n^2$ pepes labeled $1, 2, \ldots, n^2$ with pairwise distinct speeds. You would like to set up some races to find out the relative speed of these pepes.
In one race, you can choose exactly $n$ distinct pepes and make them race against each other. After each race, you will only know the fastest pepe of these $n$ pepes.
Can you order the $n^2-n+1$ fastest pepes in at most $2n^2 - 2n + 1$ races? Note that the slowest $n - 1$ pepes are indistinguishable from each other.
Note that the interactor is adaptive. That is, the relative speeds of the pepes are not fixed in the beginning and may depend on your queries. But it is guaranteed that at any moment there is at least one initial configuration of pepes such that all the answers to the queries are consistent.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 10^4$ ). The description of the test cases follows.
The only line of each test case contains a single integer $n$ ( $2 \le n \le 20$ ) — the number of pepes in one race.
After reading the integer $n$ for each test case, you should begin the interaction.
It is guaranteed that the sum of $n^3$ over all test cases does not exceed $3 \cdot 10^5$ .
The only line of each test case contains a single integer $n$ ( $2 \le n \le 20$ ) — the number of pepes in one race.
After reading the integer $n$ for each test case, you should begin the interaction.
It is guaranteed that the sum of $n^3$ over all test cases does not exceed $3 \cdot 10^5$ .
输出格式
To set up a race, print a line with the following format:
- $\mathtt{?}\,x_1\,x_2 \ldots x_n$ ( $1 \le x_i \le n^2$ , $x_i$ are pairwise distinct) — the labels of the pepes in the race.
After each race, you should read a line containing a single integer $p$ ( $1\le p\le n^2$ ) — the label of the fastest pepe in the race.
When you know the $n^2-n+1$ fastest pepes, print one line in the following format:
- $\mathtt{!}\,p_1\,p_2 \ldots p_{n^2 - n + 1}$ ( $1 \le p_i \le n^2$ , $p_i$ are pairwise distinct)
where $p$ is the sequence of these pepe's labels in descending order of speed.After that, move on to the next test case, or terminate the program if no more test cases are remaining.
If your program performs more than $2n^2 - 2n + 1$ races for one test case or makes an invalid race, you may receive a Wrong Answer verdict.
After printing a query do not forget to output the end of the line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see the documentation for other languages.
Hack format
For hacks, use the following format.
The first line should contain $t$ — the number of test cases.
The first line of each test case should contain an integer $n$ followed by the string manual.
The second line of each test case should contain a permutation $a_1,a_2,\ldots,a_{n^2}$ of the integers from $1$ to $n^2$ . $a_i > a_j$ if and only if pepe $i$ has a faster speed than pepe $j$ .
As an example, the hack format for the example input is: $\mathtt{1}\\\mathtt{2}~\mathtt{manual}\\\mathtt{1}~\mathtt{2}~\mathtt{3}~\mathtt{4}$
- $\mathtt{?}\,x_1\,x_2 \ldots x_n$ ( $1 \le x_i \le n^2$ , $x_i$ are pairwise distinct) — the labels of the pepes in the race.
After each race, you should read a line containing a single integer $p$ ( $1\le p\le n^2$ ) — the label of the fastest pepe in the race.
When you know the $n^2-n+1$ fastest pepes, print one line in the following format:
- $\mathtt{!}\,p_1\,p_2 \ldots p_{n^2 - n + 1}$ ( $1 \le p_i \le n^2$ , $p_i$ are pairwise distinct)
where $p$ is the sequence of these pepe's labels in descending order of speed.After that, move on to the next test case, or terminate the program if no more test cases are remaining.
If your program performs more than $2n^2 - 2n + 1$ races for one test case or makes an invalid race, you may receive a Wrong Answer verdict.
After printing a query do not forget to output the end of the line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see the documentation for other languages.
Hack format
For hacks, use the following format.
The first line should contain $t$ — the number of test cases.
The first line of each test case should contain an integer $n$ followed by the string manual.
The second line of each test case should contain a permutation $a_1,a_2,\ldots,a_{n^2}$ of the integers from $1$ to $n^2$ . $a_i > a_j$ if and only if pepe $i$ has a faster speed than pepe $j$ .
As an example, the hack format for the example input is: $\mathtt{1}\\\mathtt{2}~\mathtt{manual}\\\mathtt{1}~\mathtt{2}~\mathtt{3}~\mathtt{4}$
输入输出样例
输入 #1
1 2 2 4 4 3 2
输出 #1
? 1 2 ? 3 4 ? 2 4 ? 2 3 ? 2 1 ! 4 3 2
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted