atcoder#AGC016D. [AGC016D] XOR Replace
[AGC016D] XOR Replace
Score : points
Problem Statement
There is a sequence of length : . Here, each is a non-negative integer.
Snuke can repeatedly perform the following operation:
- Let the XOR of all the elements in be . Select an integer () and replace with .
Snuke's objective is to match with another sequence . Here, each is a non-negative integer.
Determine whether the objective is achievable, and find the minimum necessary number of operations if the answer is positive.
Constraints
- and are integers.
Input
Input is given from Standard Input in the following format:
Output
If the objective is achievable, print the minimum necessary number of operations.
Otherwise, print -1
instead.
3
0 1 2
3 1 0
2
At first, the XOR of all the elements of is . If we replace with , becomes .
Now, the XOR of all the elements of is . If we replace with , becomes , which matches .
3
0 1 2
0 1 2
0
2
1 1
0 0
-1
4
0 1 2 3
1 0 3 2
5