Robot Rock Band (Small)
InterviewTime limit5sMemory limit512 MB
Count quadruples with one element from each of four lists whose bitwise XOR equals K.
- Level
Medium5 of 10
- Topics
- Hash map, Brute force
- Solved
- No attempts yet
Problem
You manage Xorbitant, the world's first robot rock band. The band has four positions, and N robots audition for each position. No robot auditions for more than one position. Every robot carries a number, and several robots can carry the same number, just as 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 a trendy number K.
Count the sets of four robots, one per position, that give the band this property. Stated precisely, you are given four lists A, B, C, D of N numbers each, and you must count the ways to pick from A, from B, from C, and from D so that . Here is the bitwise XOR operation.
Input
The first line holds the number of test cases T. T test cases follow. Each case begins with one line holding two space separated integers N and K. Four more lines follow, each with N space separated integers, the numbers of the robots auditioning for one position in the band.
Limits
- Every robot number is between and , inclusive.
Output
For each test case, print one line in the form Case #x: y, where x is the test case number starting from 1 and y is the number of bands that meet the condition.
Note
In the first test case of the first example, the combined XOR has to be 3, so the robot taken from the second list must be 2 and the robot taken from the fourth list must be 1. Either of the two robots numbered 0 can be taken from the first list and from the third list, so bands meet the condition. All four bands read as (0, 2, 0, 1), but they count as different because the robots picked from the lists differ.