Editorial for AAAA 1 P1 - Even-Odd Sort
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Since we only care about the parity of the value , we can consider taking
and all
values modulo
. Additionally, since any remaining number can be taken from the list, we do not care about its order. In other words, We only need to consider the amount of even and odd values in the list.
Subtask 1
In this subtask, all values in the list are odd.
Consider the player who gets the last turn. The final number in the list that they must use on this turn is guarenteed to be odd. Let this number be .
If they choose to update to
, the parity of
will flip from even to odd or vice versa.
If they choose to update to
, the parity of
will stay the same.
Thus, they have complete control over the parity of . Since this is the final turn, they can force the parity of
to be whatever is needed for them to win.
The player who gets the last turn is determined by the parity of . Thus, if
is odd,
Steven wins. Otherwise, if is even,
Todd wins.
Time Complexity:
Subtask 2
We once again consider two cases based on the parity of .
Case 1:
is odd
Since is odd, Steven gets the last turn. Let the final number in the list that he must use on this turn be
.
If is odd, then as shown in Subtask 1, Steven has complete control over the parity of
and can force it to be even, winning the game.
If is even, Steven can choose to update
to
, which will also force
to be even, winning the game.
So, no matter what number remains in the list, Steven can always force
to be even.
Thus, if is odd, Steven always wins.
Case 2:
is even
Since is even, Todd gets the last turn.
Consider Steven's final turn before this last turn. As shown in Case 1, he can always force to be even after his turn no matter what number
he uses from the list.
Note that it may be possible for Steven to make odd after this second last turn. However, it is never optimal, since Todd will always be able to win if
is odd on his final turn using the following strategy:
- If
is odd, then Todd can choose to update
to
, so as to keep
odd.
- If
is even, then Todd can choose to update
to
, which also keeps
odd.
Thus, we can assume that Steven will always force to be even before Todd's final turn.
Now, Todd can only win if the final number remaining in the list is odd.
- If
is odd, then Todd can choose to update
to
, flipping
from even to odd.
- If
is even, then both
and
are even numbers, and Todd has no choice but to lose.
We can now infer that Steven's strategy leading up to the final turn is to use up as many odd numbers as possible so that Todd does not have an odd number as his final remaining number. Similarly, Todd's strategy leading up to the final turn is to first use up all the even numbers to potentially have an odd number saved for his final turn.
Since Steven has turns in total, he can use up at most
odd numbers. Thus, if the amount of odd numbers in the starting list is strictly greater than
, Steven will not be able to use up all the odd numbers and Todd can save an odd number for his final turn, winning the game.
Summary
Todd wins if and only if is even and the amount of odd numbers in the starting list is strictly greater than
. Otherwise,
Steven wins.
Time Complexity:
Bonus
Author Commentary
This was indeed a leftover problem idea from UTS Open '24. However, in the old version, I wanted Steven and Todd to place and
signs in between numbers of a fixed sequence and to evaluate the final expression with order of operations. That turned out to be too hard for me to solve, so here we are.
Comments