lce4113 与安全游戏AI (CI翻译)
This is an interactive problem. Additionally, hacks are disabled for this problem.
There are two hidden integers $b$ and $v$ such that $b \in \{0,1\}$ and $0 \le v \lt 2^{30}.$ There is also a hidden operation $\mathrm{ty},$ which is either $\&$ or $|.$ Here, $\&$ denotes the bitwise AND operation. Additionally, $|$ denotes the bitwise OR operation.
Your goal is to guess $b.$
你的目标是猜出 $b$。AI (CI翻译)
The interaction proceeds as follows:
交互过程如下:AI (CI翻译)
- First, you send a value
$x$to the interactor, such that$0 \le x \lt 2^{30}$. - The interactor sends back
$v\,\mathrm{ty}\,x$. Formally, it will send back$o(v,x)$, where$$o(v,x) = \begin{cases}v\,\&\,x & \mathrm{ty} = \& \\ v\,|\,x & \mathrm{ty} = |.\end{cases}$$ - You then send two numbers
$m_0$and$m_1$, where$0 \le m_0, m_1 \lt 2^{30}.$ - Finally, the interactor will send back
$m_b \oplus v,$where$\oplus$denotes the bitwise XOR operation.
- 首先,你向交互器发送一个值
$x$,满足$0 \le x \lt 2^{30}$。 - 交互器返回
$v\,\mathrm{ty}\,x$。形式化地说,它将返回$o(v,x)$,其中$$o(v,x) = \begin{cases}v\,\&\,x & \mathrm{ty} = \& \\ v\,|\,x & \mathrm{ty} = |.\end{cases}$$ - 接着,你发送两个数
$m_0$和$m_1$,满足$0 \le m_0, m_1 \lt 2^{30}$。 - 最后,交互器将返回
$m_b \oplus v$,其中$\oplus$表示按位异或运算。
After the interaction, you have to output $b$.
交互结束后,你需要输出 $b$。AI (CI翻译)
Input
输入
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). The description of the test cases follows. Note that this is the only initial input given.
每个测试包含多个测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^5$)。接下来是各测试用例的描述。注意,这是唯一一次提供的初始输入。AI (CI翻译)
Interaction
交互
AI (CI翻译)First, you need to output a single integer $x \, (0 \le x \lt 2^{30})$ — the initial value to send to the interactor.
首先,你需要输出一个整数 $x \, (0 \le x \lt 2^{30})$——发送给交互器的初始值。AI (CI翻译)
In response, you will receive a single integer $o\,(0 \le o \lt 2^{30})$ — the result $o(v,x)$ of the operation $v\,\mathrm{ty}\,x.$
作为回应,你将收到一个整数 $o\,(0 \le o \lt 2^{30})$——运算 $v\,\mathrm{ty}\,x$ 的结果 $o(v,x)$。AI (CI翻译)
Next, you will send a single line containing two integers $m_0, m_1\,(0 \le m_0, m_1 \lt 2^{30}).$
接下来,你需要输出一行,其中包含两个整数 $m_0, m_1\,(0 \le m_0, m_1 \lt 2^{30})$。AI (CI翻译)
Finally, receive a single integer $r\,(0 \le r \lt 2^{30})$ — the value of $m_b \oplus v.$
最后,接收一个整数 $r\,(0 \le r \lt 2^{30})$——$m_b \oplus v$ 的值。AI (CI翻译)
Note that the interactor is partially adaptive — in particular, the choice of $v$ may be determined by the initial input $x$, but all hidden values will be fixed after.
注意,交互器是部分自适应的——特别地,$v$ 的取值可能由初始输入 $x$ 决定,但所有隐藏值在此之后都会固定。AI (CI翻译)
After printing each query do not forget to output the end of line and flush$^{\text{∗}}$ the output. Otherwise, you will get Idleness limit exceeded verdict.
输出每次询问后,不要忘记输出换行并刷新$^{\text{∗}}$输出缓冲区。否则,你将收到 Idleness limit exceeded 判定。AI (CI翻译)
If, at any interaction step, you read $-1$ instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.
如果在交互的任意步骤中,你读取到 $-1$ 而不是有效数据,你的程序必须立即退出。这意味着你的程序将因无效询问或其他错误而收到 Wrong answer。未能退出可能导致任意判定,因为你的程序会继续从已关闭的流中读取数据。AI (CI翻译)
$^{\text{∗}}$To flush, use: fflush(stdout) or cout.flush() in C++; sys.stdout.flush() in Python; see the documentation for other languages.
$^{\text{∗}}$刷新输出缓冲区的方法:在 C++ 中使用 fflush(stdout) 或 cout.flush();在 Python 中使用 sys.stdout.flush();其他语言请参阅相关文档。AI (CI翻译)
Note
说明
AI (CI翻译)The example interaction proceeds as follows:
样例交互过程如下:AI (CI翻译)
SolutionInteractorExplanation$3$There are $3$ test cases.$2$The solution chooses $x = 2$.$0$The interactor sends back $x\,\mathrm{ty}\,v = 2\,\&\,1 = 0.The interactor responds with $$314$ $159$The solution sends $m_0 = 314$ and $m_1 = 159.$$315$$m_b \oplus v = m_0 \oplus v = 315.The next test case begins. The solution chooses $$0$The solution determines $b = 0.$$3$$x = 3$.$3$The interactor sends back $x\,\mathrm{ty}\,v = 3\,|\,1 = 3.The interactor responds with $$12$ $34$The solution sends $m_0 = 12$ and $m_1 = 34.$$35$$m_b \oplus v = m_1 \oplus v = 35.The final test case begins. The solution chooses $$1$The solution determines $b = 1.$$0$$x = 0$.$5$The interactor sends back $x\,\mathrm{ty}\,v = 0\,|\,5 = 5.The interactor responds with $$0$ $0$The solution sends $m_0 = 0$ and $m_1 = 0.$$5$$m_b \oplus v = m_1 \oplus v = 5.$$1$The solution determines $b = 1.$
程序交互器解释$3$有 $3$ 个测试用例。$2$程序选择 $x = 2$。$0$交互器返回 $x\,\mathrm{ty}\,v = 2\,\&\,1 = 0.交互器返回 $$314$ $159$程序发送 $m_0 = 314$ 和 $m_1 = 159.$$315$$m_b \oplus v = m_0 \oplus v = 315. $$0$程序确定 $b = 0$。$3$下一个测试用例开始。程序选择 $x = 3$。$3$交互器返回 $x\,\mathrm{ty}\,v = 3\,|\,1 = 3.$$12$$34$程序发送 $m_0 = 12$ 和 $m_1 = 34.程序确定 $$35$交互器返回 $m_b \oplus v = m_1 \oplus v = 35.$$1$$b = 1$。$0$最后一个测试用例开始。程序选择 $x = 0$。$5$交互器返回 $x\,\mathrm{ty}\,v = 0\,|\,5 = 5.交互器返回 $$0$ $0$程序发送 $m_0 = 0$ 和 $m_1 = 0.$$5$$m_b \oplus v = m_1 \oplus v = 5.$$1$程序确定 $b = 1$。AI (CI翻译)
Note that the queries made by the example solution may not yield enough information to determine the hidden bit $b.$ Additionally the empty lines in the example interaction are given for readability and need not be outputted in the solution.
注意,样例程序进行的询问可能不足以确定隐藏位 $b$。此外,样例交互中的空行仅为便于阅读而添加,程序无需输出这些空行。AI (CI翻译)
The hidden values in the test cases are given below.
各测试用例中的隐藏值如下。AI (CI翻译)
Test #$v$$b$$\mathrm{ty}$$1$$1$$0$$\&$$2$$1$$1$$|$$3$$5$$1$$|$
测试编号$v
AI (CI翻译)$$b$$\mathrm{ty}$$1$$1$$0$$\&$$2$$1$$1$$|$$3$$5$$1$$|$
样例
3
0
315
3
35
5
5
2
314 159
0
3
12 34
1
0
0 0
1
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。