#5050. Problem 1. All Pairs Similarity
Problem 1. All Pairs Similarity
Problem 1. All Pairs Similarity
USACO 2024 December Contest, Platinum
Note: The memory limit for this problem is 512MB, twice the default.
Farmer John's () cows are each assigned a bitstring of length that is not all zero (). Different cows may be assigned the same bitstring.
The Jaccard similarity of two bitstrings is defined as the number of set bits in their bitwise intersection divided by the number of set bits in their bitwise union. For example, the Jaccard similarity of the bitstrings and would be .
For each cow, output the sum of her bitstring's Jaccard similarity with each of the cows' bitstrings including her own, modulo . Specifically, if the sum is equal to a rational number where and are integers sharing no common factors, output the unique integer in the range such that is divisible by .
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains and .
The next lines each contain an integer , representing a cow associated with the length- binary representation of .
INPUT FORMAT (input arrives from the terminal / stdin):
Output the sum modulo for each cow on a separate line.
SAMPLE INPUT:
4 2 1 1 2 3
SAMPLE OUTPUT:
500000006 500000006 500000005 500000006
The cows are associated with the following bitstrings: $[\texttt{01}, \texttt{01}, \texttt{10}, \texttt{11}]$.
For the first cow, the sum is $\text{sim}(1,1)+\text{sim}(1,1)+\text{sim}(1,2)+\text{sim}(1,3)=1+1+0+1/2\equiv 500000006\pmod{10^9+7}$.
The second cow's bitstring is the same as the first cow's, so her sum is the same as above.
For the third cow, the sum is
$\text{sim}(2,1)+\text{sim}(2,1)+\text{sim}(2,2)+\text{sim}(2,3)=0+0+1+1/2\equiv 500000005\pmod{10^9+7}$.
SCORING: Inputs 2-15: There will be two test cases for each of .
Problem credits: Benjamin Qi