Codeforces Round 901 (Div. 1)
B
Jellyfish and Math
Codeforces
2400
原题
← AC →
翻译中…

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 \oplus y$,
  • $y := y \oplus m$.
翻译中…

Here $\&$ denotes the bitwise AND operation, $|$ denotes the bitwise OR operation and $\oplus$ denotes the bitwise XOR operation.

翻译中…

Now Jellyfish asks you for the minimum number of operations such that $(x,y)=(c,d)$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \leq t \leq 10^5$). The description of the test cases follows.

翻译中…

The only line of each test case contains five integers, $a$, $b$, $c$, $d$ and $m$ ($0 \leq a, b, c, d, m \lt 2^{30}$).

翻译中…

Output

翻译中…

For each test case, output a single integer — the minimum number of operations. If this cannot be achieved, output $-1$ instead.

翻译中…

Note

翻译中…

In the first test case, we can do the operation $y = x \oplus 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 \oplus m$.

翻译中…

样例

Input #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
Output #1
1
-1
2
-1
-1
2
1
4
1
3
InputCopy OutputCopy
题目信息
题号
1874B
时间限制
2 s
内存限制
512 MB
标签
位运算
暴力
DFS 及类似
动态规划
图论
最短路

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。