Find by Query

AtCoder
IDabc299_d
Time2000ms
Memory256MB
Difficulty
This is an **interactive task**, where your program and the judge interact via Standard Input and Output. The judge has a string of length $N$ consisting of $0$ and $1$: $S = S_1S_2\ldots S_N$. Here, $S_1 = 0$ and $S_N = 1$. You are given the length $N$ of $S$, but not the contents of $S$. Instead, you can ask the judge at most $20$ questions as follows. * Choose an integer $i$ such that $1 \leq i \leq N$ and ask the value of $S_i$. Print an integer $p$ such that $1 \leq p \leq N-1$ and $S_p \neq S_{p+1}$. It can be shown that such $p$ always exists under the settings of this problem. ## Constraints * $2 \leq N \leq 2 \times 10^5$ ## Input And Output First, receive the length $N$ of the string $S$ from Standard Input: $N$ Then, you get to ask the judge at most $20$ questions as described in the problem statement. Print each question to Standard Output in the following format, where $i$ is an integer satisfying $1 \leq i \leq N$: ? $i$ In response to this, the value of $S_i$ will be given from Standard Input in the following format: $S_i$ Here, $S_i$ is $0$ or $1$. When you find an integer $p$ satisfying the condition in the problem statement, print it in the following format, and immediately quit the program: ! $p$ If multiple solutions exist, you may print any of them. [samples] ## 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 $S$ will be fixed at the start of the interaction and will not be changed according to your questions or other factors.
API Response (JSON)
{
  "problem": {
    "name": "Find by Query",
    "description": {
      "content": "This is an **interactive task**, where your program and the judge interact via Standard Input and Output. The judge has a string of length $N$ consisting of $0$ and $1$: $S = S_1S_2\\ldots S_N$. Here, ",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc299_d"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "This is an **interactive task**, where your program and the judge interact via Standard Input and Output.\nThe judge has a string of length $N$ consisting of $0$ and $1$: $S = S_1S_2\\ldots S_N$. Here, ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments