408854: GYM103351 D Set game

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Set gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Greetings and welcome... I want to play a game.

The author of the problem has a secret integer $$$d$$$ which you should guess.

You will maintain a set of integers which is initially empty.

There are 2 types of queries you can ask:

  1. Add an integer $$$x$$$ ($$$0 \leq x \leq 10^9$$$) to the set.
  2. Remove an integer $$$x$$$ ($$$0 \leq x \leq 10^9$$$) from the set.

You cannot add a number if it is already present in the set and you cannot remove a number if it is not present in the set.

After each query the author will tell you if there are two elements $$$x$$$ and $$$y$$$ in the set, so that $$$x - y = d$$$.

You will play this game $$$T$$$ times. The author guarantees that the secret integer $$$d$$$ for each game will always be in range $$$[1, 500]$$$.

Unfortunately, you don't have much time so you can only ask up to $$$100$$$ queries in each game.

Interaction

The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 25$$$) — number of the games.

After that you should start making queries:

  • In case your program is making a query to add an element $$$x$$$, it should print '+ x'.
  • In case your program is making a query to remove an element $$$x$$$, it should print '- x'.
  • In case your program is ready to guess the secret number $$$d$$$ for this game, it should print '! d'.

For the first two types of queries interactor will respond with:

  • 'Incorrect' if you add a number which is already in the set or remove a number which is not in the set.
  • 'YES' if there is a pair of elements $$$(x, y)$$$ in the set so that $$$x - y = d$$$
  • 'NO' if there is no pair of elements $$$(x, y)$$$ in the set so that $$$x - y = d$$$

After you print the answer for the game, the interactor will respond with 'Correct' if you guessed author's number and 'Incorrect' otherwise.

Please note that if you get the 'Incorrect' response you should immediately stop the program. Otherwise you may get unpredictable verdicts.

Remember to flush the output every time. Use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
ExampleInput
2

NO

NO

YES

YES

YES

Correct

NO

YES

Correct
Output

+ 2

+ 3 

+ 8

+ 7

- 8

! 5

+ 37

+ 0

! 37

加入题单

算法标签: