No.1187 Emperor Penguin
タグ : / 解いたユーザー数 150
作問者 :
penguinman
/ テスター :
kaage
Notice
This problem is an interactive problem.
Problem Statement
Penguinman is very kind and rarely gets angry. So, feeling frustrated, you have decided to relieve your stress by hitting Penguinman.
Whether Penguinman gets angry is determined by the following criteria.
- There exists an integer $N$ between $1$ and $10^3$, inclusive, such that he always gets angry if he is hit $N$ or more times.
- Penguinman dislikes an integer $D$ between $2$ and $10^9$, inclusive, so if the final number of times he is hit is a positive integer multiple of $D$, he gets angry regardless of how it compares with $N$.
- He does not get angry only if neither of the above $2$ conditions applies.
Penguinman is scary when angry, so in order not to make him angry, you have decided to find out how many times you can hit him by asking in advance, "Will you get angry if the final number of times you are hit is $X$?"
Penguinman is busy, so the number of questions is limited. Specifically, you can ask at most $25$ questions.
By asking some questions, find the maximum number of times you can hit Penguinman.
Constraints
- $1≤N≤10^3$
- $2≤D≤10^9$
- $N,D$ are integers
- $N-1$ is not a multiple of $D$
Input and Output
The submitted program (hereafter called the submission) must consist only of the following $2$ types of queries.
- Question query
- "out". This means that Penguinman gets angry if he is finally hit $X$ times.
- "safe". This means that Penguinman does not get angry if he is finally hit $X$ times.
- Answer query
\(?\) \(X\)
It must be output in the format above. This is a question to Penguinman asking, "Will you get angry if you are finally hit $X$ times?", and it must satisfy $0\leq X\leq 10^9$.
In response, the judge's program (hereafter called the judge) gives one of the following $2$ answers via standard input.
\(!\) \(X\)
It must be output in the format above. This represents the answer to the test case: "The maximum number of times Penguinman can be hit is $X$."
In this case as well, $0\leq X\leq 10^9$ must be satisfied.
Notes
- Flush standard output after each output. Otherwise, you may get TLE.
- Terminate the program immediately after outputting the answer query. Otherwise, the behavior of the judge is undefined.
- If a query sent does not satisfy the conditions above, the interaction between the judge and the submission is automatically terminated. The behavior of the judge in this case is also undefined.
- In this problem, no input is given initially. Therefore, the interaction with the judge begins when the submission sends a query.
- The answer query is not counted toward the number of questions.
Sample
Sample 1
Output of the submission
? 1 ? 2 ? 3 ? 4 ? 5 ? 6 ! 3
Output of the judge
safe out safe out out out
In this case, $N,D$ are $4,2$.
The maximum number of times you can hit him is $3$, so $3$ is output in the answer query.
This submission is judged AC.
Sample 2
Output of the submission
? 1 ? 2 ? 3 ? 4 ? 5 ! 0
Output of the judge
out out out out out
In this case, $N$ is $1$, and the value of $D$ is not uniquely determined.
The maximum number of times you can hit him is $0$, so $0$ is output in the answer query.
This submission is judged AC. Note that there are cases where you cannot hit him even once, that is, you can hit him only $0$ times.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。