CF1874B.Jellyfish and Math

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Jellyfish is given the non-negative integers aa , bb , cc , dd and mm . Initially (x,y)=(a,b)(x,y)=(a,b) . Jellyfish wants to do several operations so that (x,y)=(c,d)(x,y)=(c,d) .

For each operation, she can do one of the following:

  • x:=x&yx := x\,\&\,y ,
  • x:=xyx := x\,|\,y ,
  • y:=xyy := x \oplus y ,
  • y:=ymy := 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)(x,y)=(c,d) .

输入格式

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

The only line of each test case contains five integers, aa , bb , cc , dd and mm ( 0a,b,c,d,m<2300 \leq a, b, c, d, m < 2^{30} ).

输出格式

For each test case, output a single integer — the minimum number of operations. If this cannot be achieved, output 1-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=xyy = x \oplus y .

In the second test case, it is not possible to change (x,y)=(1,2)(x,y)=(1,2) using any sequence of operations.

In the third test case, we can do the operation x=x&yx = x\,\&\,y followed by the operation y=ymy = y \oplus m .

首页