#P16519. [GKS 2015 #E] Robot Rock Band

    ID: 18894 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2015位运算折半搜索 meet in the middleSTLGoogle Kick Start

[GKS 2015 #E] Robot Rock Band

Problem Description

You're the manager of Xorbitant, the world's first robot rock band. There will be four positions in the band, and there are NN robots auditioning for each position. (No robot is auditioning for more than one position.) Every robot has a number, and multiple robots might have the same number, just as two people can have the same name.

You know from market research that your robot audiences won't care how well the robot band members make music, how handsome they are, or what scandalous things the tabloids say about them. Instead, the audience will be checking to see whether the four members' numbers, when bitwise XORed together, equal a certain trendy number KK.

How many different sets of four robots (one for each position) is it possible to choose so that the band will have this property? More specifically, given four lists A, B, C, D containing NN numbers each, how many ways are there to choose one number aa from list A, one number bb from list B, and so on, such that a ^ b ^ c ^ d = K? (Here ^ represents the bitwise XOR operation.)

Input Format

The first line of the input gives the number of test cases, TT. TT test cases follow. Each case begins with one line with two space-separated integers, NN and KK, as described above. Then, four more lines follow. Each has NN space-separated integers and represents the ID numbers of the robots auditioning for a certain position in the band.

Output Format

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and yy is the number of different bands that meet the conditions.

2
2 3
0 0
2 0
0 0
0 1
2 0
1 10
1 10
1 10
1 10
Case #1: 4
Case #2: 8

Hint

In sample case #1, in order to get a combined bitwise XOR of 33, the robot chosen from the second list must be 22, and the robot chosen from the fourth list must be 11. For the first and third lists, either of the two 00 robots can be chosen, so there are 2×2=42 \times 2 = 4 possible bands that meet the criteria. Note that even though all of these bands are of the form (0,2,0,1)(0, 2, 0, 1), they are considered different because the selections from the lists were different.

Limits

1T101 \le T \le 10.

0K1090 \le K \le 10^9.

00 \le all robot numbers 109\le 10^9.

Small dataset (Test Set 1 - Visible)

1N501 \le N \le 50.

Large dataset (Test Set 2 - Hidden)

1N10001 \le N \le 1000.