Editorial for LCC '25 Contest 1 S5 - Moonlight's Box Challenge
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Notice that since each dimension is independent, all we need to determine is whether or not there's a time such that for all dimensions, 's position is on one of the endpoints of this dimension. This implies that for any dimension, the direction is oscillating between
and
. It can be shown that it doesn't matter if we reverse directions, as we're just trying to determine whether or not 's position is divisible by
.
Subtask 1
Notice that the positions in modulo
repeats after
units of time. This means that we can run a brute force algorithm to check each unit of time to see if
.
This can be done in O() time. An optimized search will pass under Python, Java or C++.
Subtask 2
This subtask was to help users visualize the problem.
Since the LCMs are now too large to individually check each point in time, we can only consider when the current position is on one of the edges. This can be simulated with a priority queue, pushing in the current position and the time elapsed to get to the current position, and checking each position to see if it lies on a corner.
This can be simulated in O() time.
Subtask 3
Note that the dimensions with need to be handled separately.
Note that it is now not feasible to check each dimension individually. After doing some math, we can determine that the congruence , where
represents a dimension such that
, and
represents the final coordinate of the
th dimension.
To check if this system of congruences has a solution, we can check pairwise equations to check if there exists a solution to the two congruences. It can be shown that if all pairwise congruences have a solution, then the entire system has a solution.
This can be done in O() time.
Note: A very optimized solution to subtask 2 can pass the final subtask, but is not feasible to do within contest(I could not come up with a solution that passes).
Comments