Editorial for COCI '23 Contest 2 #4 Kuglice
Submitting an official solution before solving the problem yourself is a bannable offence.
Prepared by: Fran Babić
In the first subtask, it holds that there are at most two different colors in the sequence. The first ball taken will definitely score 1:0
, 1:1
, and 2:0
. Solving the first subtask boils down to decomposing it into 3 different cases:
- All elements in the sequence are the same, i.e., the number of different colors is one.
In this case, the game result will be1:0
. - The element at the left end of the sequence is different from the one at the right end, i.e.,
.
Whichever element Marin chooses in the first move, Josip can take the one from the other end of the sequence, which is different from the one Marin took. We can see that in this case, the game result will be1:1
. - Not all elements in the sequence are the same, and the elements at the ends of the sequence are the same (
).
It is easy to see that the answer will depend on the parity of the longest prefix and suffix of equal elements.
Let
Observation. For the current game state
Using this, we can write a function
Comments