On each cell of a grid, we place a car, which faces in one of the four cardinal directions. In a move, one chooses a car that does not have a car immediately in front of it, and slides it one cell forward. If a move would cause a car to exit the grid, the car is removed instead. The cars are placed so that there exists a sequence of moves that eventually removes all the cars from the grid. Across all such starting configurations, determine the maximum possible number of moves to do so.
Solution
Let . The answer is . A construction for an grid instead (so ): ! Label the rows and columns from 1 to , and let denote the cell at row , column . The cars can be cleared in the following order: - Remove all cars in row . - For each row , move the upward-facing cars in row once, then remove all remaining cars in row . - Now all cars in the upper-left quarter of the grid can be removed, then those in the upper-right, then those in the lower-right. Moreover, this starting configuration indeed requires moves to clear. Now we show this is the best possible. Take some starting configuration for which it is possible for all cars to leave. For each car , let denote the number of moves makes before it exits. Partition the grid into concentric square "rings" , such that consists of all cells on the border of the grid, consists of the four central cells: ! Since all cars can be removed, each contains some car which points away from the ring, so that . Now fix some ring . Then: - If car is at a corner of , we have . - Each car on the bottom edge of , say at for , can be paired with the opposing car at . As cannot point toward each other, we have Likewise, we can pair each car at with the opposing car at , getting the same bound. - If , then pairing it with the opposing car gives . Note that this is less than the previous bound, by at least Summing the contributions from the four corners, each pair among the non-corner cars, and a pair involving an outward-facing car gives One can verify that this evaluates to ; alternatively, note that equality holds in our construction, so summing over all must yield the desired tight upper bound.