Editorial for Wesley's Anger Contest 6 Problem 2 - Cheap Christmas Lights
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
First, we note that toggle operations are commutative so Wesley has the ability to "accumulate" switch usages, such that instead of using one switch per second for the first seconds, he can simply perform switch usages during the second. We then notice that it will take at most seconds to flip all the switches off, since at most lights will be on by the second and Wesley will accumulate up to switch usages by then.
Subtask 1
For the first subtask, we keep track of the state of each light throughout the first seconds, and after the second we check if there are at most lights turned on by iterating through our array storing the lights' states. Be aware that the answer could be greater than .
Time Complexity:
Subtask 2
Instead of iterating through the array storing lights' states, we can use a counter to keep track of how many lights are on at any given moment. We no longer need to recount the number of lights turned on at every iteration.
Time Complexity:
Comments