Editorial for CPC '19 Contest 1 P1 - Distance
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.
Author:
Subtask 1
For the first subtask, you can just brute force all possible ways you can visit all the houses and output any that matches the constraints of the problem.
Time Complexity:
Subtask 2
The trick here is to start from , then go to , then back to , then go to , then back to , etc. If you look at the sequence here, you'll notice the absolute difference between adjacent values is constantly decreasing:
Absolute Value of Differences:
Time Complexity:
Comments