CF1874B.Jellyfish and Math
普及/提高-
通过率:0%
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) .
输入格式
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 ).
输出格式
For each test case, output a single integer — the minimum number of operations. If this cannot be achieved, output −1 instead.
输入输出样例
输入#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 .