Codeforces Raif Round 1 (Div. 1 + Div. 2)
H
Rotary Laser Lock
Codeforces
3500
原题
← G2→
翻译中…

This is an interactive problem.

翻译中…

To prevent the mischievous rabbits from freely roaming around the zoo, Zookeeper has set up a special lock for the rabbit enclosure. This lock is called the Rotary Laser Lock.

翻译中…

The lock consists of $n$ concentric rings numbered from $0$ to $n-1$. The innermost ring is ring $0$ and the outermost ring is ring $n-1$. All rings are split equally into $nm$ sections each. Each of those rings contains a single metal arc that covers exactly $m$ contiguous sections. At the center of the ring is a core and surrounding the entire lock are $nm$ receivers aligned to the $nm$ sections.

翻译中…

The core has $nm$ lasers that shine outward from the center, one for each section. The lasers can be blocked by any of the arcs. A display on the outside of the lock shows how many lasers hit the outer receivers.

翻译中…

image

翻译中…

In the example above, there are $n=3$ rings, each covering $m=4$ sections. The arcs are colored in green (ring $0$), purple (ring $1$), and blue (ring $2$) while the lasers beams are shown in red. There are $nm=12$ sections and $3$ of the lasers are not blocked by any arc, thus the display will show $3$ in this case.

翻译中…

Wabbit is trying to open the lock to free the rabbits, but the lock is completely opaque, and he cannot see where any of the arcs are. Given the relative positions of the arcs, Wabbit can open the lock on his own.

翻译中…

To be precise, Wabbit needs $n-1$ integers $p_1,p_2,\ldots,p_{n-1}$ satisfying $0 \leq p_i \lt nm$ such that for each $i$ $(1 \leq i \lt n)$, Wabbit can rotate ring $0$ clockwise exactly $p_i$ times such that the sections that ring $0$ covers perfectly aligns with the sections that ring $i$ covers. In the example above, the relative positions are $p_1 = 1$ and $p_2 = 7$.

翻译中…

To operate the lock, he can pick any of the $n$ rings and rotate them by $1$ section either clockwise or anti-clockwise. You will see the number on the display after every rotation.

翻译中…

Because his paws are small, Wabbit has asked you to help him to find the relative positions of the arcs after all of your rotations are completed. You may perform up to $15000$ rotations before Wabbit gets impatient.

翻译中…

Input

翻译中…

The first line consists of 2 integers $n$ and $m$ $(2 \leq n \leq 100, 2 \leq m \leq 20)$, indicating the number of rings and the number of sections each ring covers.

翻译中…

Interaction

翻译中…

To perform a rotation, print on a single line "? x d" where $x$ $(0 \leq x \lt n)$ is the ring that you wish to rotate and $d$ $(d \in \{-1,1\})$ is the direction that you would like to rotate in. $d=1$ indicates a clockwise rotation by $1$ section while $d=-1$ indicates an anticlockwise rotation by $1$ section.

翻译中…

For each query, you will receive a single integer $a$: the number of lasers that are not blocked by any of the arcs after the rotation has been performed.

翻译中…

Once you have figured out the relative positions of the arcs, print ! followed by $n-1$ integers $p_1, p_2, \ldots, p_{n-1}$.

翻译中…

Do note that the positions of the rings are predetermined for each test case and won't change during the interaction process.

翻译中…

After printing a query do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded verdict.

翻译中…

To do this, use:

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

Hacks:

翻译中…

To hack, use the following format of test:

翻译中…

The first line should contain two integers $n$ and $m$.

翻译中…

The next line of should contain $n-1$ integers $p_1,p_2,\ldots,p_{n-1}$: relative positions of rings $1,2,\ldots,n-1$.

翻译中…

Note

翻译中…

For the first test, the configuration is the same as shown on the picture from the statement.

翻译中…

After the first rotation (which is rotating ring $0$ clockwise by $1$ section), we obtain the following configuration:

翻译中…

image

翻译中…

After the second rotation (which is rotating ring $2$ counter-clockwise by $1$ section), we obtain the following configuration:

翻译中…

image

翻译中…

After the third rotation (which is rotating ring $1$ clockwise by $1$ section), we obtain the following configuration:

翻译中…

image

翻译中…

If we rotate ring $0$ clockwise once, we can see that the sections ring $0$ covers will be the same as the sections that ring $1$ covers, hence $p_1=1$.

翻译中…

If we rotate ring $0$ clockwise five times, the sections ring $0$ covers will be the same as the sections that ring $2$ covers, hence $p_2=5$.

翻译中…

Note that if we will make a different set of rotations, we can end up with different values of $p_1$ and $p_2$ at the end.

翻译中…

样例

Input #1
3 4

4

4

3
Output #1
? 0 1

? 2 -1

? 1 1

! 1 5
InputCopy OutputCopy
题目信息
题号
1428H
时间限制
1 s
内存限制
256 MB
标签
二分
交互题

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