A13139 | Strange Device
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
This problem is interactive.
We have hidden an array $a$ of $n$ pairwise different numbers (this means that no two numbers are equal). You can get some information about this array using a new device you just ordered on Amazon.
This device can answer queries of the following form: in response to the positions of $k$ different elements of the array, it will return the position and value of the $m$ -th among them in the ascending order.
Unfortunately, the instruction for the device was lost during delivery. However, you remember $k$ , but don't remember $m$ . Your task is to find $m$ using queries to this device.
You can ask not more than $n$ queries.
Note that the array $a$ and number $m$ are fixed before the start of the interaction and don't depend on your queries. In other words, interactor is not adaptive.
Note that you don't have to minimize the number of queries, and you don't need to guess array $a$ . You just have to guess $m$ .
We have hidden an array $a$ of $n$ pairwise different numbers (this means that no two numbers are equal). You can get some information about this array using a new device you just ordered on Amazon.
This device can answer queries of the following form: in response to the positions of $k$ different elements of the array, it will return the position and value of the $m$ -th among them in the ascending order.
Unfortunately, the instruction for the device was lost during delivery. However, you remember $k$ , but don't remember $m$ . Your task is to find $m$ using queries to this device.
You can ask not more than $n$ queries.
Note that the array $a$ and number $m$ are fixed before the start of the interaction and don't depend on your queries. In other words, interactor is not adaptive.
Note that you don't have to minimize the number of queries, and you don't need to guess array $a$ . You just have to guess $m$ .
输入格式
The first line contains two integers $n$ and $k$ ( $1\le k < n \le 500$ ) — the length of the array and the number of the elements in the query.
It is guaranteed that number $m$ satisfies $1\le m \le k$ , elements $a_1, a_2, \dots, a_n$ of the array satisfy $0\le a_i \le 10^9$ , and all of them are different.
It is guaranteed that number $m$ satisfies $1\le m \le k$ , elements $a_1, a_2, \dots, a_n$ of the array satisfy $0\le a_i \le 10^9$ , and all of them are different.
输出格式
You begin the interaction by reading $n$ and $k$ .
To ask a question about elements on positions $x_1, x_2, \dots, x_k$ , in a separate line output
$?$ $x_1$ $x_2$ $x_3$ ... $x_k$
Numbers in the query have to satisfy $1 \le x_i \le n$ , and all $x_i$ have to be different. Don't forget to 'flush', to get the answer.
In response, you will receive two integers $pos$ and $a_{pos}$ — the position in the array $a$ of the $m$ -th in ascending order element among $a_{x_1}, a_{x_2}, \dots, a_{x_k}$ , and the element on this position.
In case your query is invalid or you asked more than $n$ queries, the program will print $-1$ and will finish interaction. You will receive a Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.
When you determine $m$ , output
$!$ $m$
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:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see documentation for other languages.
Hack format
For the hacks use the following format:
The first line has to contain three integers $n, k, m$ ( $1 \le m \le k < n \le 500$ ) — the length of the array, number of elements in the query, and which in the ascending order number the device returns.
In the next line output $n$ integers $a_1, a_2, \dots, a_n$ ( $0\le a_i \le 10^9$ ) — the elements of the array. They have to be pairwise different.
To ask a question about elements on positions $x_1, x_2, \dots, x_k$ , in a separate line output
$?$ $x_1$ $x_2$ $x_3$ ... $x_k$
Numbers in the query have to satisfy $1 \le x_i \le n$ , and all $x_i$ have to be different. Don't forget to 'flush', to get the answer.
In response, you will receive two integers $pos$ and $a_{pos}$ — the position in the array $a$ of the $m$ -th in ascending order element among $a_{x_1}, a_{x_2}, \dots, a_{x_k}$ , and the element on this position.
In case your query is invalid or you asked more than $n$ queries, the program will print $-1$ and will finish interaction. You will receive a Wrong answer verdict. Make sure to exit immediately to avoid getting other verdicts.
When you determine $m$ , output
$!$ $m$
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:
- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see documentation for other languages.
Hack format
For the hacks use the following format:
The first line has to contain three integers $n, k, m$ ( $1 \le m \le k < n \le 500$ ) — the length of the array, number of elements in the query, and which in the ascending order number the device returns.
In the next line output $n$ integers $a_1, a_2, \dots, a_n$ ( $0\le a_i \le 10^9$ ) — the elements of the array. They have to be pairwise different.
输入输出样例
输入 #1
4 3 4 9 4 9 4 9 1 2
输出 #1
? 2 3 4 ? 1 3 4 ? 1 2 4 ? 1 2 3 ! 3
In the example, $n = 4$ , $k = 3$ , $m = 3$ , $a = [2, 0, 1, 9]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted