codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

727C.md (2662B)


      1 Source: https://codeforces.com/problemset/problem/727/C
      2 
      3 C. Guess the Array
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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).
     22 
     23 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*.
     24 
     25 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*.
     26 
     27 It is easy to prove that it is always possible to guess the array using at most *n* requests.
     28 
     29 Write a program that will guess the array *a* by making at most *n* requests.
     30 
     31 Interaction
     32 
     33 In each test your program should guess a single array.
     34 
     35 The input starts with a line containing integer *n* (3 ≤ *n* ≤ 5000) — the length of the array. Your program should read it at first.
     36 
     37 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.
     38 
     39 * 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*.
     40 * 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 105), where *a**i* is the *i*-th element of the array *a*.
     41 
     42 The response on a request is a single integer equal to *a**i* + *a**j*, printed on a separate line.
     43 
     44 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.
     45 
     46 Do not forget about flush operation after each printed line.
     47 
     48 After you program prints the guessed array, it should terminate normally.
     49 
     50 Example
     51 
     52 Input
     53 
     54 ```
     55 5  
     56    
     57 9  
     58    
     59 7  
     60    
     61 9  
     62    
     63 11  
     64    
     65 6  
     66  
     67 ```
     68 
     69 Output
     70 
     71 ```
     72    
     73 ? 1 5  
     74    
     75 ? 2 3  
     76    
     77 ? 4 1  
     78    
     79 ? 5 2  
     80    
     81 ? 3 4  
     82    
     83 ! 4 6 1 5 5
     84 ```
     85 
     86 Note
     87 
     88 The format of a test to make a hack is:
     89 
     90 * The first line contains an integer number *n* (3 ≤ *n* ≤ 5000) — the length of the array.
     91 * The second line contains *n* numbers *a*1, *a*2, ..., *a**n* (1 ≤ *a**i* ≤ 105) — the elements of the array to guess.