Editorial for JOI '22 Open P1 - Seesaw
Submitting an official solution before solving the problem yourself is a bannable offence.
Author: Akihito Yoneyama
Subtask 1
We can solve this subtask by calculating all possible ways to remove the weights. The time complexity of
this algorithm is .
Subtask 2
We use the Two Pointers Technique. We increase the lower bound of the position of the barycenter. We shall
see how the upper bound increases. Let be the state where the weights are remaining in the interval
.
We need to check whether the vertex
and the vertex
are connected in the grid graph. There are
possibilities for the upper bounds and the lower bounds. The connectedness of a graph can be checked in
time. The total time complexity is
.
Subtask 3
In the algorithm for Subtask 2, we consider the change of path from the state to each
. When the
lower bound increases by
, if the vertex
of the previous lower bound is contained in the path, we delete
it and add a new vertex
to the path. Simulating this process, we solve this subtask in
time.
Subtask 4
We can decrease the number of the candidates of paths. More precisely, we need only consider paths between the following two paths.
- A path which greedily deletes the leftmost weights while the barycenter does not become larger than the original barycenter.
- A path which greedily deletes the rightmost weights while the barycenter does not become smaller than the original barycenter.
Since there are only vertices between them, by the same algorithm as Subtask 3, we can solve this subtask
in
time.
Comments