CF1934D1.XOR Break — Solo Version
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the solo version of the problem. Note that the solution of this problem may or may not share ideas with the solution of the game version. You can solve and get points for both versions independently.
You can make hacks only if both versions of the problem are solved.
Given an integer variable x with the initial value of n. A single break operation consists of the following steps:
- Choose a value y such that 0<y<x and 0<(x⊕y)<x.
- Update x by either setting x=y or setting x=x⊕y.
Determine whether it is possible to transform x into m using a maximum of 63 break operations. If it is, provide the sequence of operations required to achieve x=m.
You don't need to minimize the number of operations.
Here ⊕ denotes the bitwise XOR operation.
这是该问题的单人版本。请注意,本题的解法可能与游戏版本的解法思路相同,也可能不同。你可以独立求解并分别获得两个版本的分数。
仅当两个版本的问题均已被解决时,你才可进行 hack。
给定一个整数变量 x,其初始值为 n。一次“break”操作包含以下步骤:
- 选择一个值 y,满足 0<y<x 且 0<(x⊕y)<x;
- 将 x 更新为 y 或 x⊕y(即令 x=y 或 x=x⊕y)。
请判断是否能在最多 63 次 break 操作内将 x 变为 m。若可以,请给出实现 x=m 所需的操作序列。
你无需最小化操作次数。
此处 ⊕ 表示按位异或运算(bitwise XOR)。
输入格式
The first line contains one positive integer t (1≤t≤104) — the number of test cases.
Each test case consists of a single line containing two integers n and m (1≤m<n≤1018) — the initial value of x and the target value of x.
第一行包含一个正整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例由一行组成,包含两个整数 n 和 m(1≤m<n≤1018)—— x 的初始值和目标值。
输出格式
For each test case, output your answer in the following format.
If it is not possible to achieve m in 63 operations, print −1.
Otherwise,
The first line should contain k (1≤k≤63) — where k is the number of operations required.
The next line should contain k+1 integers — the sequence where variable x changes after each break operation. The 1-st and k+1-th integers should be n and m, respectively.
对于每个测试用例,请按以下格式输出你的答案:
如果无法在 63 次操作内得到 m,则输出 −1。
否则:
第一行应包含 k(1≤k≤63),其中 k 为所需的操作次数。
第二行应包含 k+1 个整数——即变量 x 在每次“break”操作后所经历的序列。第 1 个和第 k+1 个整数应分别为 n 和 m。
输入输出样例
输入#1
3 7 3 4 2 481885160128643072 45035996273704960
输出#1
1 7 3 -1 3 481885160128643072 337769972052787200 49539595901075456 45035996273704960
说明/提示
In the first test case n=7, for the first operation x=7 if we choose y=3 then (7⊕3)<7, hence we can update x with 3 which is equal to m.
In the second test case n=4, for the first operation x=4.
If we choose:
- y=1 then (4⊕1)>4
- y=2 then (4⊕2)>4
- y=3 then (4⊕3)>4
Hence we can't do the first operation and it is impossible to make x=2.
在第一个测试用例中,n=7,第一次操作时 x=7;若我们选择 y=3,则 (7⊕3)<7,因此我们可以将 x 更新为 3,而 3 恰好等于 m。
在第二个测试用例中,n=4,第一次操作时 x=4。
若我们选择:
- y=1,则 (4⊕1)>4
- y=2,则 (4⊕2)>4
- y=3,则 (4⊕3)>4
因此我们无法执行第一次操作,也就不可能使 x=2。
输入解题思路,AI测评打分。不知道怎么写?