Blindfold
Time limit1sMemory limit128 MB
Given a grid with obstacles and a fixed sequence of forward/turn moves, mark every walkable square that can be a final position for some unknown start and heading.
- Level
Medium6 of 10
- Topics
- Simulation, Bit manipulation, Matrix, Implementation
- Solved
- No attempts yet
Problem
Rose and Colin are playing a game in their backyard. Because the backyard is rectangular, we can view it as a grid with rows and columns. Some squares contain obstacles.
The game works as follows. Colin covers his eyes with a blindfold, and Rose carries him to some square of the backyard, setting him down so that he faces north, south, east, or west. Colin does not know this initial position or direction. Rose then tells Colin to make a sequence of moves, where each move is one of:
F— move forward one square in the direction he is facing.L— turn 90 degrees counter-clockwise, staying on the same square.R— turn 90 degrees clockwise, staying on the same square.
After making all of these moves, Colin ends up at some final position. Determine every square that could be his final position. You may assume that Colin's initial position, final position, and all intermediate positions always lie inside the backyard and never on a square that contains an obstacle, and that Colin always faces a direction parallel to the sides of the backyard (north, south, east, or west).
Input
The first line contains and the second line contains . The next lines describe the backyard, each with characters: a . denotes a square Colin may walk through, and an X denotes a square with an obstacle. The next line contains the number of moves , followed by lines describing Colin's moves. Each line holds a single character: F, L, or R.
Output
Print the backyard grid as lines of characters. Mark each obstacle square with X, each square that could be Colin's final position with *, and every other walkable square with ..