Robot Vacuum 2
Time limit12sMemory limit1024 MB
Given a grid warehouse with boxes and a start cell, output a command string of length N that maximizes the number of distinct cells the vacuum visits.
- Level
Hard9 of 10
- Topics
- Greedy, Simulation, Graph, Brute force
- Solved
- No attempts yet
Problem
The problem Robot Vacuum was about counting how many cells a robot vacuum visits in a grid. In this problem, you are given the grid and the length of the command sequence, and must instead find a command sequence that makes the vacuum visit as many different cells as possible.
Your score depends on how well your solution performs compared to the judges' solution. This means that getting points may be difficult, but collecting partial points does not have to be very hard.
Input
The input consists of test cases.
- The first line contains an integer (), the number of the test case ( is the example case below).
- The second line contains three integers: () and (), the number of rows and columns in the grid-shaped warehouse, and (), the length of the command sequence.
- The following lines describe the grid-shaped warehouse. The -th of these lines contains characters describing the -th row. Each character is either a period "
." if a cell is empty, a hash "#" if a cell contains a box, or "O" if the cell is the robot's starting position. Exactly one cell is guaranteed to contain "O". In addition, every cell on the edge of the grid is guaranteed to be "#".
Output
Print one line containing a string of length made up of the characters "^", ">", "v", "<". This is the command sequence the vacuum will follow.