Robot Rock Band (Large)
InterviewTime limit7sMemory limit512 MB
Count quadruples with one element from each of four lists whose bitwise XOR equals K.
- Level
Medium5 of 10
- Topics
- Hash map, Bit manipulation
- Solved
- No attempts yet
Problem
You manage Xorbitant, the world's first robot rock band. The band has four positions, and robots audition for each position. No robot auditions for more than one position. Every robot carries a number, and two robots can carry the same number, the way two people can share a name.
Market research says the robot audience does not care how well the members play, how they look, or what the tabloids print about them. The audience checks one thing: whether the bitwise XOR of the four members' numbers equals the trendy number .
How many different sets of four robots, one per position, give the band that property? Put another way, four lists , , , hold numbers each. Count the ways to pick one number from , one number from , one number from , and one number from so that , where is bitwise XOR.
Input
The first line holds the number of test cases . Each test case starts with a line holding two space separated integers and . Four lines follow. Each holds space separated integers, the numbers of the robots auditioning for one position. The four lines give the lists , , , in that order.
Limits
- Every robot number is between and .
Output
For each test case, print one line in the form Case #x: y, where is the test case number starting from 1 and is the number of bands that meet the condition.
Hint
In the first test case of example 1, the XOR has to be , so the robot taken from the second list must be and the robot taken from the fourth list must be . Either of the two robots works for the first and the third list, so bands meet the condition. All four bands read , but they count as different because the robots picked from the lists differ.