Time Limit: 2 sec / Memory Limit: 256 MB
Xing Yang has N toys, each of which with a type Ti
He also has N displays, each of which can only hold a toy type Di
In 1 operation, he can replace the type of toy i Ti with the value K, where K is the XOR of the types of all toys.
Determine if XY can make the types of all toys such that Ti = Di for all toys, and find how many operations he will require.
Input is given from Standard Input in the following format:
N T1 T2 ... TN D1 D2 ... DN
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 a is 3. If we replace T1 with 3, T becomes (3, 1, 2).
Now, the XOR of all the elements of a is 0. If we replace T3 with 0, T becomes (3, 1, 0), which matches b.
3 0 1 2 0 1 2
0
2 1 1 0 0
-1
4 0 1 2 3 1 0 3 2
5
Subtask | Score |
---|---|
1 | 0 |
2 | 100 |