Editorial for DMOPC '15 Contest 3 P2 - Cheesecake Distribution
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.
Author:
Knowledge required: array processing, basic math
This was slightly trickier than the usual P2. Notice that we're only concerned with the final state, not the steps we take to get there.
Let's denote as the total number of slices. Right off the bat, we can see that if is not divisible by , it is Impossible
.
If it is divisible, we know that each person has to have slices at the end.
The observation is that each turn, no matter who's giving to whom, we're moving two steps closer to the end state.
The answer is therefore .
Time Complexity:
Comments