問題一覧 > 通常問題

No.246 Questions and Answers

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 256 MB / リアクティブ問題 (詳しくはこちら)
タグ : (AC するまで非表示) / 解いたユーザー数 334
作問者 : 紙ぺーぱー
お気に入りにしたユーザー ProblemId : 551 / 自分の提出
問題文最終更新日: 2026-06-26 01:59:42
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 115 (順位表) の他の問題:
この問題はリアクティブ形式の問題です!通常の問題と形式が異なることに注意してください!!!

Problem Statement

Kamipeipaa-kun loves a certain integer $x$ in the range from $1$ to $10^{9}$. However, being mean, he has never told anyone what it is.
Instead, you are allowed to ask the question "is $x$ greater than or equal to a certain integer $y$?". Kamipeipaa-kun has promised to answer such questions honestly.
Kamipeipaa-kun is busy, so he is willing to answer at most $100$ questions. Guess the integer Kamipeipaa-kun loves using at most $100$ questions.

Input and Output

The program you submit (hereafter, the answer program) must print 2 types of queries to standard output.
The queries are the question query, which asks whether $x$ is greater than or equal to a certain integer $y$, and the answer query, which answers that $x$ is a certain integer $y$.
The format of the question query is
"$?$ $y$",
and the format of the answer query is
"$!$ $y$".

End each query with a newline.
When you make a question query, the response program returns the result to the standard input of the answer program. If $x$ is greater than or equal to $y$, $1$ is given as input; otherwise, $0$ is given.
Flush the output after printing. If you do not flush, the response program may be unable to process the input and the time limit may be exceeded, which may result in a wrong answer. Also, always receive the result after making a question query. Otherwise, the response program may be unable to process the input, which may cause a wrong answer.

After making the answer query, terminate the program immediately. Otherwise, the judge's time limit may be exceeded, which may result in a wrong answer. This problem uses a special judge. Your submission is considered correct if it terminates within the judge's time limit, the number of questions is at most $100$, and the value $y$ printed in the answer query matches $x$.

Notes

  • In question queries and answer queries, the result is undefined if $y$ is outside the range of a $64$bit signed integer.
  • The judge's time limit is $2$ seconds, and this includes the reaction time of the response program.
  • Printing anything other than the 2 types of queries results in a wrong answer.
  • Output to standard error is regarded as neither a question query, an answer query, nor invalid output.
Example Program
import sys
iter = 1
res = 1
while iter <= 4:
    print ("? %d" % iter)
    sys.stdout.flush()
    res = int(input())
    iter += 1
if res==1:
    print("! %d" % res)
else:
    print("! %d" % 2)
sys.stdout.flush()

Sample

Sample 1
Output of the answer program
? 1
? 2
? 3
? 4
! 2
Output of the response program
1
1
0
0

On line 1, the answer program prints a question query, and the response program outputs that it is at least 1.
On line 2, the answer program prints a question query, and the response program outputs that it is at least 2.
On line 3, the answer program prints a question query, and the response program outputs that it is not at least 3.
On line 4, the answer program prints a question query, and the response program outputs that it is not at least 4.
On line 5, the answer program prints an answer query, answering that $x$ is 2.
Since 2 is the only integer that is at least 2 and not at least 3, this is correct.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。