A10610 | Guess the Array
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output).
In this problem you should guess an array $a$ which is unknown for you. The only information you have initially is the length $n$ of the array $a$ .
The only allowed action is to ask the sum of two elements by their indices. Formally, you can print two indices $i$ and $j$ (the indices should be distinct). Then your program should read the response: the single integer equals to $a_{i}+a_{j}$ .
It is easy to prove that it is always possible to guess the array using at most $n$ requests.
Write a program that will guess the array $a$ by making at most $n$ requests.
In this problem you should guess an array $a$ which is unknown for you. The only information you have initially is the length $n$ of the array $a$ .
The only allowed action is to ask the sum of two elements by their indices. Formally, you can print two indices $i$ and $j$ (the indices should be distinct). Then your program should read the response: the single integer equals to $a_{i}+a_{j}$ .
It is easy to prove that it is always possible to guess the array using at most $n$ requests.
Write a program that will guess the array $a$ by making at most $n$ requests.
输入格式
无
输出格式
In each test your program should guess a single array.
The input starts with a line containing integer $n$ ( $3<=n<=5000$ ) — the length of the array. Your program should read it at first.
After that your program should print to the standard output the requests about the sum of two elements or inform that the array is guessed.
- In case your program is making a request to ask the sum of two elements, it should print line in the format "? i j" ( $i$ and $j$ are distinct integers between $1$ and $n$ ), where $i$ and $j$ are indices in the array $a$ .
- In case your program informs that the array is guessed, it should print line in the format " $! a_{1} a_{2} ... a_{n}$ " (it is guaranteed that all $a_{i}$ are positive integers not exceeding $10^{5}$ ), where $a_{i}$ is the $i$ -th element of the array $a$ .
The response on a request is a single integer equal to $a_{i}+a_{j}$ , printed on a separate line.
Your program can do at most $n$ requests. Note that the final line « $! a_{1} a_{2} ... a_{n}$ » is not counted as a request.
Do not forget about flush operation after each printed line.
After you program prints the guessed array, it should terminate normally.
The input starts with a line containing integer $n$ ( $3<=n<=5000$ ) — the length of the array. Your program should read it at first.
After that your program should print to the standard output the requests about the sum of two elements or inform that the array is guessed.
- In case your program is making a request to ask the sum of two elements, it should print line in the format "? i j" ( $i$ and $j$ are distinct integers between $1$ and $n$ ), where $i$ and $j$ are indices in the array $a$ .
- In case your program informs that the array is guessed, it should print line in the format " $! a_{1} a_{2} ... a_{n}$ " (it is guaranteed that all $a_{i}$ are positive integers not exceeding $10^{5}$ ), where $a_{i}$ is the $i$ -th element of the array $a$ .
The response on a request is a single integer equal to $a_{i}+a_{j}$ , printed on a separate line.
Your program can do at most $n$ requests. Note that the final line « $! a_{1} a_{2} ... a_{n}$ » is not counted as a request.
Do not forget about flush operation after each printed line.
After you program prints the guessed array, it should terminate normally.
输入输出样例
输入 #1
5 9 7 9 11 6
输出 #1
? 1 5 ? 2 3 ? 4 1 ? 5 2 ? 3 4 ! 4 6 1 5 5
The format of a test to make a hack is:
- The first line contains an integer number $n$ ( $3<=n<=5000$ ) — the length of the array.
- The second line contains $n$ numbers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=10^{5}$ ) — the elements of the array to guess.
- The first line contains an integer number $n$ ( $3<=n<=5000$ ) — the length of the array.
- The second line contains $n$ numbers $a_{1},a_{2},...,a_{n}$ ( $1<=a_{i}<=10^{5}$ ) — the elements of the array to guess.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted