A - Grid Turing Robot Editorial
by
wyyinput
AHC056 Editorial (365 th)
Initial idea
First ignore coloring. For each step, simply increment the state and move to the next position. We find the shortest path for the route, but this approach is obviously inefficient.
Submission. \(\color{red}{122242}\) points.
Minor optimizations
Obviously we don’t need to modify the state when reaching the destination, so one state can be saved.
Submission. \(\color{red}{122192}\) points.
Further observation: the final segment with unchanged direction only needs one state.
Submission. \(\color{red}{122049}\) points.
Since the final straight segment with constant direction requires only one state, we can enumerate this segment at the end and find the minimum sum of state count and color count. (This code does not seem to consider the constraint \(T\); if used as the final solution, it will likely lose points.)
Submission. \(\color{red}{121976}\) points.
Early advanced ideas
Introduce colors.
We can assign one color to each cell, and each cell starts its state from 0. The total number of states is then determined by the maximum state value among all cells.
Submission. \(\color{red}{15556}\) points. A huge improvement.
Many details can be optimized further. For example, cells never visited do not need colors. Tuning this gives \(\color{red}{13675}\) points.
Submission. \(\color{red}{13675}\) points.
Major breakthrough
Many cells have visit counts far smaller than \(p\), the maximum visit count of any cell. Assigning a separate color to each of them wastes colors. We may merge colors of some cells, provided that after merging the total visit count for each color remains at most \(p\). There is a pitfall here: the starting cell must be handled specially. Its initial state is 0; if the start cell is merged with others, we cannot guarantee its state starts at 0.
Submission. \(\color{red}{4809}\) points.
Deeper thoughts
Why must the total visit count per color after merging be bounded by \(p\), the maximum cell visit count? Can we split a single cell across multiple colors? We can enumerate the allowed maximum visit count after merging, compute the answer for each case, and take the minimum.
Submission. \(\color{red}{4550}\) points.
posted:
last update:
