Editorial for COCI '14 Contest 2 #2 Utrka
Submitting an official solution before solving the problem yourself is a bannable offence.
A naive approach to solving this problem would be the following algorithm:
For each contestant from the list
if the contestant's name is on the ranking list
mark contestant
cross out contestant from the ranking list
Output unmarked contestant
This implementation has a time complexity of
To win all points, it was necessary to notice that the name of the contestant that didn't manage to finish the race is going to occur an odd number of times in the input, whereas the names of all the other contestants are going to occur an even number of times.
If we think this through, we will see that an analogous claim holds for every letter in the name of the wanted contestant. For example, if we observe the number of occurrences of initial letters of all the contestants, we will see that all the letters except the initial one of the wanted contestant occur an even number of times. This claim leads us to the following idea:
Let
In the style of the main character of the sixth task – "Can it be pimped up? Of course it can!" Let us recall some properties of the binary operation
Combining these properties, it is easy to deduce that it is sufficient, for every index, output
Comments
For python users, consider using the Counter class from collections rather than lists.