Codeforces Round 499 (Div. 2)
D
Rocket
Codeforces
未评级
原题
← CE →
翻译中…

This is an interactive problem.

翻译中…

Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet.

翻译中…

Let's define $x$ as the distance to Mars. Unfortunately, Natasha does not know $x$. But it is known that $1 \le x \le m$, where Natasha knows the number $m$. Besides, $x$ and $m$ are positive integers.

翻译中…

Natasha can ask the rocket questions. Every question is an integer $y$ ($1 \le y \le m$). The correct answer to the question is $-1$, if $x \lt y$, $0$, if $x=y$, and $1$, if $x \gt y$. But the rocket is broken — it does not always answer correctly. Precisely: let the correct answer to the current question be equal to $t$, then, if the rocket answers this question correctly, then it will answer $t$, otherwise it will answer $-t$.

翻译中…

In addition, the rocket has a sequence $p$ of length $n$. Each element of the sequence is either $0$ or $1$. The rocket processes this sequence in the cyclic order, that is $1$-st element, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $1$-st, $2$-nd, $3$-rd, $\ldots$, $(n-1)$-th, $n$-th, $\ldots$. If the current element is $1$, the rocket answers correctly, if $0$ — lies. Natasha doesn't know the sequence $p$, but she knows its length — $n$.

翻译中…

You can ask the rocket no more than $60$ questions.

翻译中…

Help Natasha find the distance to Mars. Assume, that the distance to Mars does not change while Natasha is asking questions.

翻译中…

Your solution will not be accepted, if it does not receive an answer $0$ from the rocket (even if the distance to Mars is uniquely determined by the already received rocket's answers).

翻译中…

Input

翻译中…

The first line contains two integers $m$ and $n$ ($1 \le m \le 10^9$, $1 \le n \le 30$) — the maximum distance to Mars and the number of elements in the sequence $p$.

翻译中…

Interaction

翻译中…

You can ask the rocket no more than $60$ questions.

翻译中…

To ask a question, print a number $y$ ($1\le y\le m$) and an end-of-line character, then do the operation flush and read the answer to the question.

翻译中…

If the program reads $0$, then the distance is correct and you must immediately terminate the program (for example, by calling exit(0)). If you ignore this, you can get any verdict, since your program will continue to read from the closed input stream.

翻译中…

If at some point your program reads $-2$ as an answer, it must immediately end (for example, by calling exit(0)). You will receive the "Wrong answer" verdict, and this will mean that the request is incorrect or the number of requests exceeds $60$. If you ignore this, you can get any verdict, since your program will continue to read from the closed input stream.

翻译中…

If your program's request is not a valid integer between $-2^{31}$ and $2^{31}-1$ (inclusive) without leading zeros, then you can get any verdict.

翻译中…

You can get "Idleness limit exceeded" if you don't print anything or if you forget to flush the output.

翻译中…

To flush the output buffer you can use (after printing a query and end-of-line):

翻译中…
  • fflush(stdout) in C++;
  • System.out.flush() in Java;
  • stdout.flush() in Python;
  • flush(output) in Pascal;
  • See the documentation for other languages.
翻译中…

Hacking

翻译中…

Use the following format for hacking:

翻译中…

In the first line, print $3$ integers $m,n,x$ ($1\le x\le m\le 10^9$, $1\le n\le 30$) — the maximum distance to Mars, the number of elements in the sequence $p$ and the current distance to Mars.

翻译中…

In the second line, enter $n$ numbers, each of which is equal to $0$ or $1$ — sequence $p$.

翻译中…

The hacked solution will not have access to the number $x$ and sequence $p$.

翻译中…

Note

翻译中…

In the example, hacking would look like this:

翻译中…

5 2 3

翻译中…

1 0

翻译中…

This means that the current distance to Mars is equal to $3$, Natasha knows that it does not exceed $5$, and the rocket answers in order: correctly, incorrectly, correctly, incorrectly ...

翻译中…

Really:

翻译中…

on the first query ($1$) the correct answer is $1$, the rocket answered correctly: $1$;

翻译中…

on the second query ($2$) the correct answer is $1$, the rocket answered incorrectly: $-1$;

翻译中…

on the third query ($4$) the correct answer is $-1$, the rocket answered correctly: $-1$;

翻译中…

on the fourth query ($5$) the correct answer is $-1$, the rocket answered incorrectly: $1$;

翻译中…

on the fifth query ($3$) the correct and incorrect answer is $0$.

翻译中…

样例

Input #1
5 2
1
-1
-1
1
0
Output #1
1
2
4
5
3
InputCopy OutputCopy
题目信息
题号
1011D
时间限制
1 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。