Editorial for Arcadia Computing Contest 2 P3 - Alternato


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: htoshiro

Since William can undo any move that Ayman performs, the key observation is that Ayman can only win if he can win in one of two scenarios:

  1. Ayman has already won.
  2. Ayman wins after making 1 move.

Subtask 1

We can check if scenario 1 is satisfied by looping through the values. If this is not the case, we can brute force adding/subtracting 1 to each value. We can then check all of the values again to see if they now satisfy the requirements. If no modification satisfies the requirement, it is impossible for Ayman to win.

Time Complexity: O(N^{2})

Subtask 2

Instead of checking all of the values in the array again to see if the requirements are satisfied, we can notice that the only possible values that change from good to bad values or vice-versa are the values at the index we modify and it's adjacent neighbours. We can check to see if they are originally bad values, and after modification, if the values now satisfy the requirements.

Time Complexity: O(N)


Comments

There are no comments at the moment.