First, Great job, the code is easy on the eyes.

Second, Are you sure that the 2/25 cases are failing due to time limit exceeded and not due to a wrong answer? If yes, since you are iterating through all rows and columns for a reset, how about memcpy-ing the whole initialized 2D array each time when you need a reset and see what it does to the performance. If it doesn't, I would try memoization. When that too fails, I would assume probably a more efficient algorithm exists to solve the problem.