2024 年 12 月USACO竞赛白金组问题一—All Pairs Similarity

Farmer John's N (1≤N≤5⋅105) cows are each assigned a bitstring of length K that is not all zero (1≤K≤20). 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 11001 and 11010 would be 2/4.

For each cow, output the sum of her bitstring's Jaccard similarity with each of the N cows' bitstrings including her own, modulo 109+7. Specifically, if the sum is equal to a rational number a/b where a and b are integers sharing no common factors, output the unique integer x in the range [0,109+7) such that bxa is divisible by 109+7.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains N and K.

The next N lines each contain an integer i∈(0,2K), representing a cow associated with the length-K binary representation of i.

INPUT FORMAT (input arrives from the terminal / stdin):

Output the sum modulo 109+7 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: [01,01,10,11].

For the first cow, the sum is  sim(1,1)+sim(1,1)+sim(1,2)+sim(1,3)=1+1+0+1/2≡500000006(mod 109+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

sim(2,1)+sim(2,1)+sim(2,2)+sim(2,3)=0+0+1+1/2≡500000005(mod 109+7).

SCORING:

Inputs 2-15: There will be two test cases for each of K∈{10,15,16,17,18,19,20}.

Problem credits: Benjamin Qi

扫码领取USACO试题答案+详细解析

咨询一对一备赛规划

USACO竞赛考试网-二维码