Editorial for COCI '07 Contest 1 #3 Prinova
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.
Submitting an official solution before solving the problem yourself is a bannable offence.
A solution that iterates over all odd numbers from and calculates the distance to the nearest name is too slow for the given constraints.
Let us solve a modified version of the problem where the solution can be odd or even. Then the solution is one of the following:
- , for every pair
For each solution candidate, we first check if it falls inside and then find the distance to the nearest name. The solution is thus the number that maximizes that distance.
In the original problem, only odd solutions are allowed. To account for this, we simply substitute each even solution candidate with numbers and .
Comments