#abc299d. D - Find by Query
D - Find by Query
Score : points
问题描述
这是一个交互式任务,您的程序将通过标准输入和输出与裁判进行交互。
裁判手中有一个长度为 的由 和 组成的字符串:。其中, 且 。
您会得到字符串 的长度 ,但不会直接得知其具体内容。取而代之的是,您可以最多向裁判提问不超过 次,提问方式如下:
- 选择一个整数 ,满足 ,并询问 的值。
请打印出一个整数 ,满足 且 。
可以证明,在本问题的设定下,这样的 总是存在的。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
This is an interactive task, where your program and the judge interact via Standard Input and Output.
The judge has a string of length consisting of and : . Here, and .
You are given the length of , but not the contents of . Instead, you can ask the judge at most questions as follows.
- Choose an integer such that and ask the value of .
Print an integer such that and .
It can be shown that such always exists under the settings of this problem.
Constraints
Input and Output
First, receive the length of the string from Standard Input:
Then, you get to ask the judge at most questions as described in the problem statement.
Print each question to Standard Output in the following format, where is an integer satisfying :
?
In response to this, the value of will be given from Standard Input in the following format:
Here, is or .
When you find an integer satisfying the condition in the problem statement, print it in the following format, and immediately quit the program:
!
If multiple solutions exist, you may print any of them.
Notes
- Print a newline and flush Standard Output at the end of each message. Otherwise, you may get a TLE verdict.
- If there is malformed output during the interaction or your program quits prematurely, the verdict will be indeterminate.
- After printing the answer, immediately quit the program. Otherwise, the verdict will be indeterminate.
- The string will be fixed at the start of the interaction and will not be changed according to your questions or other factors.
Sample Input and Output
In the following interaction, and .
Input | Output | Description |
---|---|---|
7 | $N$ is given. | |
? 1 | Ask the value of $S_1$. | |
0 | The judge responds with $S_1 = 0$. | |
? 6 | Ask the value of $S_6$. | |
1 | The judge responds with $S_6 = 1$. | |
? 5 | Ask the value of $S_5$. | |
0 | The judge responds with $S_5 = 0$. | |
! 5 | Present $p = 5$ as an integer satisfying the condition. | |
For the presented , we have and . Thus, if the program immediately quits here, this case will be judged as correctly solved.
update @ 2024/3/10 12:24:34