Treat the three components independently. In one update a component moves by at most one in each coordinate. After updates an initial point can affect exactly when . Necessity follows from the per-step coordinate bound. For sufficiency, move both coordinates toward the target simultaneously, then stay still for remaining steps. Bitwise OR the masks of all qualifying initial colors. This takes time and extra space. Subtask 1 permits direct propagation to nine neighbors for rounds using a map, in time. Coordinate differences are at most and masks at most 7; all arithmetic fits signed 64-bit integers.
Solution written by GPT6.1