Editorial for An Animal Contest 7 P3 - Squirrel Scramble
Submitting an official solution before solving the problem yourself is a bannable offence.
Authors:
,Subtask 1
Hint 1
There are only two paths that matter from checkpointHint 2
You can either choose to use portals twice or don't use them at all to get from checkpointSolution
It can be seen that when using a portal from checkpointFor each checkpoint, we can precompute the distance to the closest portal in
Time Complexity:
Subtask 2
Solution
There are multiple solutions for this subtask, but we will go over the solution that extends the best to subtask . We claim that for any index
there exists some index
such that for every
where
it is optimal to not use any portals, and for every
where
it is optimal to use portals. A proof will be shown in the subtask
solution. In order to find the index
we can use
pointers or binary search.
Subtask 3
Solution
Now, we will prove our claim. If we use portals to go from to
the distance will be
where
is the distance to the nearest portal from checkpoint
. If we choose to walk, the distance will be
where
is the sum of path lengths from the first checkpoint to checkpoint
. In order for our claim about index
to be invalid, we need to find
integers
,
, and
where
and
and
. If we subtract the first inequality from the second inequality we get:
But,
is at most
because we can always choose to walk from
to
and then travel to
's nearest portal. So, we get:
which is a contradiction of the initial inequality
. Therefore, our claim was valid and we have solved the problem.
Comments