Editorial for COCI '11 Contest 1 #3 X3
Submitting an official solution before solving the problem yourself is a bannable offence.
The first useful observation is that individual binary digits of the friendship value are mutually independent, so they can be considered separately. If the digit of a result is equal to , a value of is added to the friendship value, otherwise is added.
A digit of the result is equal to only if the corresponding digits in extraterrestrial names differ. Since we are computing the total friendship value, we can count the number of appearances of (digit in position ) for each .
Let us denote by the number of extraterrestrials who have the digit in position in binary name notation. Then we add
to the sum of friendships, since that is exactly the number of pairs with differing digits in position , multiplied by the weight of that digit position.
Comments