Editorial for Spring Coding Bowl '22 P2 - Chicken Strips


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.

To rephrase the question more directly, we want to know if the product of the integers in the range [l,r] excluding the integers in the range [d,u] is positive, negative, zero, or nonexistent.

Subtask 1

For this subtask, loop from l to r and for each number, check if it is in the range [d,u]. If it is, ignore it. Otherwise, add it to an array. Once you are done, get the product of numbers in the array and print the proper output accordingly. Be sure to check that there are numbers in the array to avoid outputting a wrong answer.

Time Complexity: \mathcal{O}(r)

Subtask 2

For this subtask, we can think of the results as cases to handle. The product doesn't exist if d \le l and u \ge r. The product is 0 if and only if 0 is in the range [l,r] and is not in the range [d,u]. Assuming the product exists and is non-zero, the only way the product could be negative is if there are an odd number of negative numbers in the range [l,r] excluding those in the range [d,u]. All other cases result in a positive product.

Thus, the problem can be distilled down to some careful casework and counting the number of negative numbers in the range [l,r] excluding those in the range [d,u]. There are many different ways of doing this, all of which can be done with if-statements and basic arithmetic. Specific implementation details will be left as an exercise to the reader.

Time Complexity: \mathcal{O}(1)


Comments

There are no comments at the moment.