Editorial for IOI '96 P1 - A Game


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.

The following simple observation leads to a solution of the task:

Since the game board initially contains an even number of elements arranged in a sequence, when the first player moves one end of the sequence is in odd and the other end is in even position. Therefore the first player can always select an element either from an odd or even position.

The algorithm preprocesses the contents of the initial board before starting the game to compute the values OddSum and EvenSum, the sum of the elements in odd positions and the sum of the elements in even positions, respectively. If OddSum \ge EvenSum then the first player always selects from an odd position and forces the second player to select from even position. The case OddSum < EvenSum treated similarly.


Comments

There are no comments at the moment.