#BS0000111. Tìm vị trí đổi giá trị (Find by Query)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tìm vị trí đổi giá trị (Find by Query)
Find by Query
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
The judge holds a hidden binary string with and . You only know its length . Find any satisfying and . Multiple correct indices may exist; any one is accepted. The hidden string is fixed throughout the interaction.
Input
Initially the judge sends a single integer . The string is not provided. After each valid query, it responds with one character, 0 or 1, on its own line.
Output
Ask for by printing ? i with and reading the judge reply. You may ask at most 20 questions. Once a valid position is found, print ! p, flush, and immediately exit. Each message must end with a newline and be flushed.
Interactive Protocol
Lines beginning with ? are queries to the judge; lines beginning with ! are final answers. Do not print any other text to standard output.
Subtasks
- Subtask 1 (20 points): ; ; , .
- Subtask 2 (30 points): ; ; , .
- Subtask 3 (50 points): ; ; , .
Examples
Input
7
Output
? 4
? 5
? 6
! 5
This is an illustrative transcript, not a fixed output file. Hidden values are revealed only in the explanation to make the example understandable.
Explanation
Suppose and the hidden string is 0010011. Querying indices returns 0,0,1. Since and , output ! 5. Other change positions may also be valid.