Wormhole Sort

Problem-Solving

Attempt 1: I got a weird partial solution within 10 minutes of reading the problem, but I couldn't figure out anything else for the next 10 minutes that I tried to think. I then spent over 2 hours trying to understand the solution, and now I've kinda finally got it.

Attempt 2:

My initial thought was to adapt the Redistributing Gifts official solution (use dfs to find what the min widths would be (instead of just whether it would reach) -> while there is a number that isn't in the right spot, move it to the right spot and adjust the global min width if the min width to get to the right spot is lower).

The editorial solution is much more elegant and easier to implement. I think for some reason I have some subconscious prejudice against recognizing when to use binary search because I've never once used it to solve a USACO problem and often think of a gnarlier solution when an elegant one is staring me in the face.

I honestly don't know why this problem was so hard for me in the last attempt (both at first glance and in trying to understand the editorial). It's a relatively straightforward problem with a relatively straightforward editorial.

Last updated