CF727C.Guess the Array

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 aa which is unknown for you. The only information you have initially is the length nn of the array aa .

The only allowed action is to ask the sum of two elements by their indices. Formally, you can print two indices ii and jj (the indices should be distinct). Then your program should read the response: the single integer equals to ai+aja_{i}+a_{j} .

It is easy to prove that it is always possible to guess the array using at most nn requests.

Write a program that will guess the array aa by making at most nn requests.

输入格式

输出格式

In each test your program should guess a single array.

The input starts with a line containing integer nn ( 3<=n<=50003<=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" ( ii and jj are distinct integers between 11 and nn ), where ii and jj are indices in the array aa .
  • In case your program informs that the array is guessed, it should print line in the format " ! a1 a2 ... an! a_{1} a_{2} ... a_{n} " (it is guaranteed that all aia_{i} are positive integers not exceeding 10510^{5} ), where aia_{i} is the ii -th element of the array aa .

The response on a request is a single integer equal to ai+aja_{i}+a_{j} , printed on a separate line.

Your program can do at most nn requests. Note that the final line « ! a1 a2 ... an! 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 nn ( 3<=n<=50003<=n<=5000 ) — the length of the array.
  • The second line contains nn numbers a1,a2,...,ana_{1},a_{2},...,a_{n} ( 1<=ai<=1051<=a_{i}<=10^{5} ) — the elements of the array to guess.
首页