Editorial for An Animal Contest 5 P1 - Bamboo Cookies


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.

Author: sjay05

Subtask 1 + 2

Any two pairs (i, j) can be paired to sum to an even number as all a_i equal 1 or 2. The operation can be performed \lfloor \frac{n}{2} \rfloor times.

Time Complexity: \mathcal{O}(1)

Subtask 3

  • If N = 1, the answer is 0.
  • If N = 2, the answer can be 0 or 1.
  • If N = 3, the answer is 1.

Time Complexity: \mathcal{O}(1)

Subtask 4

An even number can only be created by summing two even or two odd numbers. The answer is \lfloor \frac{\text{odd}}{2} \rfloor + \lfloor \frac{\text{even}}{2} \rfloor where \text{odd} and \text{even} are the number of odd and even values in a.

Time Complexity: \mathcal{O}(N)


Comments

There are no comments at the moment.