Editorial for DMOPC '20 Contest 4 P4 - Javelin Throwing
Submitting an official solution before solving the problem yourself is a bannable offence.
Authors:
,Let
Subtask 1
For subtask 1 we can solve for each prefix separately in
We can not have less holes in a day than in the past, so transform the array to its prefix max in
The difference of holes between two days is at most
Time complexity:
Subtask 2
We can optimize the above approach.
On the
- The javelin lands in the
-th closest hole from Alice. No new hole is made. - The javelin lands between the
-th and -th holes, so a new hole is made. (It doesn't actually matter where in between.)
Since Option 1 results in fewer total holes, we want to take Option 1 as many times as possible.
We can do this greedily. Keep a running total
On the
- If
, we can take Option 1 and make no hole. In this case, . - If
, we must take Option 2 and make a hole in front of all the current holes. In this case, .
But what if
Changing throw
Since each throw is pushed and popped at most once, and the rest of the computation can be done in
Time complexity:
Problem credit: modified from https://codeforces.com/problemset/problem/924/c
Comments