XOR Pairing
Time limit2sMemory limit512 MB
Given N stones (N up to 74) with values up to 1000, pair them to minimize the sum of pairwise XORs, and count the minimum-cost pairings modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Bit manipulation, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
There are stones, and each stone has a non-negative integer written on it, where is even. Partition the stones into pairs so that each stone belongs to exactly one pair. For each pair, compute XOR : write each of and in binary, take the exclusive-or of each pair of corresponding bits, and read the result as a binary number. Sum the values XOR over all pairs. Find the minimum possible sum over all pairings, and the number of pairings that reach this minimum. Two pairings differ if one contains a pair of stones that the other does not. Two stones are different if they have different indices, even when the values on them match. The order of the pairs and the order of the stones within each pair do not matter. Since the count can be huge, output it modulo .
Input
The first line contains the even number , the number of stones, where . The second line contains the numbers written on the stones. Each number satisfies .
Output
Print one line with two numbers separated by a space. The first is the smallest possible sum of XOR over all pairings. The second is the number of pairings that achieve this minimum, modulo .