Split in Sets
Time limit1sMemory limit512 MB
Split n distinct balls into k nonempty boxes to maximize the sum of each box's bitwise AND, then count the optimal assignments modulo 10^9+7.
- Level
Medium7 of 10
- Topics
- Bit manipulation, Combinatorics, Greedy
- Solved
- No attempts yet
Problem
Zenyk is given balls with integers written on them, and also boxes. Put each ball in a box so that every box holds at least one ball. The value of a box is the bitwise AND of all integers on the balls in it. Find the maximum total sum of the values of all boxes, and the number of ways to put balls in boxes that achieve that maximum sum. The order of balls in a box does not matter. All boxes are distinct, and all balls are distinct, even when some balls have the same integer.
Input
The first line contains two integers and (). The next line contains integers ().
Output
Print two integers. The first is the maximum total sum of all boxes. The second is the number of ways to put balls in boxes that achieve this maximum, modulo .