CF1428H.Rotary Laser Lock

NOI/NOI+/CTSC

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn concentric rings numbered from 00 to n−1n-1. The innermost ring is ring 00 and the outermost ring is ring n−1n-1. All rings are split equally into nmnm sections each. Each of those rings contains a single metal arc that covers exactly mm contiguous sections. At the center of the ring is a core and surrounding the entire lock are nmnm receivers aligned to the nmnm sections.

The core has nmnm 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.

In the example above, there are n=3n=3 rings, each covering m=4m=4 sections. The arcs are colored in green (ring 00), purple (ring 11), and blue (ring 22) while the lasers beams are shown in red. There are nm=12nm=12 sections and 33 of the lasers are not blocked by any arc, thus the display will show 33 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−1n-1 integers p1,p2,…,pn−1p_1,p_2,\ldots,p_{n-1} satisfying 0≤pi<nm0 \leq p_i \lt nm such that for each ii (1≤i<n)(1 \leq i \lt n), Wabbit can rotate ring 00 clockwise exactly pip_i times such that the sections that ring 00 covers perfectly aligns with the sections that ring ii covers. In the example above, the relative positions are p1=1p_1 = 1 and p2=7p_2 = 7.

To operate the lock, he can pick any of the nn rings and rotate them by 11 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 1500015000 rotations before Wabbit gets impatient.

这是一个交互式问题。

为了防止顽皮的兔子在动物园内随意乱跑,动物园管理员为兔舍设置了一种特殊的锁,称为“旋转激光锁”。

该锁由 nn 个同心圆环组成,编号从 00 到 n−1n-1。最内层的圆环为第 00 环,最外层的圆环为第 n−1n-1 环。所有圆环均被等分为 nmnm 个扇区。每个圆环上均有一段金属弧,恰好覆盖连续的 mm 个扇区。圆环中心为一个激光核心,锁的最外围则布置有 nmnm 个接收器,与这 nmnm 个扇区一一对应。

该核心向外发射 nmnm 束激光,每束激光对应一个扇区,沿径向射出。这些激光可被任意金属弧阻挡。锁外部设有一个显示屏,用于显示最终成功抵达外圈接收器的激光束数量。

在上图示例中,共有 n=3n=3 个圆环,每个弧覆盖 m=4m=4 个扇区。三段弧分别以绿色(第 00 环)、紫色(第 11 环)和蓝色(第 22 环)标出,红色线条表示激光束。总共有 nm=12nm = 12 个扇区,其中 33 束激光未被任何弧阻挡,因此此时显示屏显示数字 33。

兔子瓦比特(Wabbit)正试图打开此锁以解救其他兔子,但整个锁完全不透明,他无法看见任何一段金属弧的位置。只要知道各段弧之间的相对位置,瓦比特便能独立打开锁。

准确地说,瓦比特需要确定 n−1n-1 个整数 p1,p2,…,pn−1p_1, p_2, \ldots, p_{n-1},满足 0≤pi<nm0 \leq p_i < nm,使得对每个 ii(1≤i<n1 \leq i < n),若将第 00 环顺时针旋转 pip_i 个扇区,则第 00 环所覆盖的扇区将与第 ii 环所覆盖的扇区完全重合。在上图示例中,对应的相对位置为 p1=1p_1 = 1 和 p2=7p_2 = 7。

操作锁时,瓦比特可任选一个圆环,并将其顺时针或逆时针旋转 11 个扇区。每次旋转后,你都将看到显示屏上更新的数字。

由于瓦比特的爪子太小,他请求你帮助他在完成所有旋转操作后,推断出各段弧之间的相对位置。你总共最多可执行 1500015000 次旋转,否则瓦比特将失去耐心。

输入格式

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

第一行包含两个整数 nn 和 mm (2≤n≤100,2≤m≤20)(2 \leq n \leq 100, 2 \leq m \leq 20),分别表示环的数量以及每个环所覆盖的段数。

输入输出样例

  • 输入#1

    3 4
    
    4
    
    4
    
    3

    输出#1

    ? 0 1
    
    ? 2 -1
    
    ? 1 1
    
    ! 1 5

说明/提示

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 00 clockwise by 11 section), we obtain the following configuration:

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

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

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

If we rotate ring 00 clockwise five times, the sections ring 00 covers will be the same as the sections that ring 22 covers, hence p2=5p_2=5.

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

对于第一次测试,配置与题目描述中的图片所示相同。

第一次旋转(即顺时针旋转第 00 个环 11 个区段)后,我们得到如下配置:

第二次旋转(即逆时针旋转第 22 个环 11 个区段)后,我们得到如下配置:

第三次旋转(即顺时针旋转第 11 个环 11 个区段)后,我们得到如下配置:

若将第 00 个环顺时针旋转一次,则第 00 个环所覆盖的区段将与第 11 个环所覆盖的区段完全相同,因此 p1=1p_1=1。

若将第 00 个环顺时针旋转五次,则第 00 个环所覆盖的区段将与第 22 个环所覆盖的区段完全相同,因此 p2=5p_2=5。

注意:若执行一组不同的旋转操作,最终所得的 p1p_1 和 p2p_2 的值也可能不同。

输入解题思路,AI测评打分。不知道怎么写?

首页