CF1874B.Jellyfish and Math
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Jellyfish is given the non-negative integers a, b, c, d and m. Initially (x,y)=(a,b). Jellyfish wants to do several operations so that (x,y)=(c,d).
For each operation, she can do one of the following:
- x:=x&y,
- x:=x∣y,
- y:=x⊕y,
- y:=y⊕m.
Here & denotes the bitwise AND operation, ∣ denotes the bitwise OR operation and ⊕ denotes the bitwise XOR operation.
Now Jellyfish asks you for the minimum number of operations such that (x,y)=(c,d).
水母得到了非负整数 a、b、c、d 和 m。初始时 (x,y)=(a,b)。水母希望执行若干次操作,使得最终 (x,y)=(c,d)。
每次操作,她可以执行以下四种操作之一:
- x:=x&y,
- x:=x∣y,
- y:=x⊕y,
- y:=y⊕m。
其中 & 表示按位与运算,∣ 表示按位或运算,⊕ 表示按位异或运算。
现在水母请你求出使 (x,y)=(c,d) 所需的最少操作次数。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤105). The description of the test cases follows.
The only line of each test case contains five integers, a, b, c, d and m (0≤a,b,c,d,m<230).
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤105)。随后是各测试用例的描述。
每个测试用例仅有一行,包含五个整数 a、b、c、d 和 m(0≤a,b,c,d,m<230)。
输出格式
For each test case, output a single integer — the minimum number of operations. If this cannot be achieved, output −1 instead.
对于每个测试用例,输出一个整数——所需的最少操作次数。如果无法实现,则输出 −1。
输入输出样例
输入#1
10 1 0 1 1 1 3 3 1 2 1 1 6 0 7 1 2 4 4 9 8 21 4 0 17 28 50 50 0 0 39 95 33 1 33 110 138 202 174 64 108 78 340 68 340 461 457 291 491 566 766
输出#1
1 -1 2 -1 -1 2 1 4 1 3
说明/提示
In the first test case, we can do the operation y=x⊕y.
In the second test case, it is not possible to change (x,y)=(1,2) using any sequence of operations.
In the third test case, we can do the operation x=x&y followed by the operation y=y⊕m.
在第一个测试用例中,我们可以执行操作 y=x⊕y。
在第二个测试用例中,无法通过任何操作序列改变 (x,y)=(1,2)。
在第三个测试用例中,我们可以先执行操作 x=x&y,再执行操作 y=y⊕m。
输入解题思路,AI测评打分。不知道怎么写?