Editorial for COCI '08 Contest 6 #4 Cuskija


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.

For simplicity, assume all input numbers are 0, 1 or 2. This does not change the result since we only need the modulus by 3.

Obviously two zeroes or a one and two cannot be adjacent. If the total number of zeroes is two or more greater than the number of ones and twos, then we can't avoid placing two zeroes together and there is no sequence. Similarly, if there are no zeroes but there are ones and twos, then we would have to place a one and two together.

Once we know it is possible, we can construct the sequence by inserting groups consisting only of ones or twos between zeroes.


Comments

There are no comments at the moment.