Make Xor
Practice
4.7 (3 votes)
Algorithms
2d dynamic programming
Bit manipulation
Dynamic programming
Problem
75% Success 441 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Bob was experimenting with an array of numbers in an effort to make a programming problem, finally he made an interesting problem but he cannot solve it, can you help Bob? 

Given an array \(A\) of \(n\) integers, Bob wants you to answer \(q\) different queries based on the given array. For each query Bob wants to know the minimum number of values he should remove from the array \(A\) to make the \(XOR\) of the remaining values in the array equal to \(x\).

NOTE: The \(XOR\) of an empty array is \(0\)

Reference: Bitwise XOR

INPUT FORMAT

The first line of the input contains an integer \(n\) (\(1 <= n <= 10^5\)) - the number of values in the array. 

The second line of the input contains \(n\) integers \(a_{1}, a_{2}, a_{3}, .. a_{n}\) \((1 <= a_{i} <= 200)\) - the values in the array. 

The third line of the input contains an integer \(q\) (\(1 <= n <= 10^5\)) - the number of queries. 

Each of the next \(q\) lines contains one integer \(x_{i}\) \((0 <= x_{i} <= 200)\) - the queried value. 

OUTPUT FORMAT

Print \(q\) integers. The \(i^{th}\) integer should represent the minimum number of values to remove from \(A\) to make the \(XOR\) equal to \(x_{i}\), or \(-1\) if it is impossible. 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
3 votes
Tags:
AlgorithmsDynamic ProgrammingMathMatrixMediumTwo dimensional
Points:30
5 votes
Tags:
2D dynamic programmingAlgorithmsDynamic Programming
Points:30
15 votes
Tags:
2D dynamic programmingAlgorithmsData StructuresDynamic Programming