Editorial for COCI '16 Contest 7 #4 Poklon
Submitting an official solution before solving the problem yourself is a bannable offence.
Let be the total mass of the weights after balancing the scale. Then the total mass of the weights on the beams of the large scale is equal to , and the sum of the weights on the beams of these scales is equal to , and so on. Generally, a beam of a scale at depth holds a load of mass .
Since some beams (at depth ) already have a weight of mass , additionally the following inequality must hold: . Finally, we have for each weight of mass , that is at depth .
We are left with efficiently comparing the numbers of the form , where and are small enough to fit in a 32-bit data type. Since these numbers in binary notation have at most 32 ones (multiplication with corresponds to left shift times), it is sufficient to just linearly iterate over the ones in the binary notation of these numbers.
Comments