Editorial for COCI '08 Contest 5 #4 Lubenica
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
We can describe the current state in the classroom with a bitmask, where the value of each bit tells whether a child received an even or odd number of melons during the previous class.
There are of these states, or about for . With a number of classes larger than this, a state is guaranteed to repeat and, once it does, it will keep looping through the same cycle. We can calculate the number of throws in one iteration of the cycle in and, with careful implementation, skip most of the iterations through the cycle.
Comments