P13935 [Lanqiao Cup 2022 Senior Java B] Memory Maze
Description
Alice has just come back from exploring an underground maze. Can you help her draw the maze map, based on her memory of the path she walked?
The maze map is based on a two-dimensional grid. Alice will tell you a series of moves she made in the maze. Each move is one of the four directions up, down, left and right, meaning that Alice walked one cell in that direction. You need to give a maze map according to these moves, satisfying the following conditions:
1. Alice can start from some empty cell inside the maze and walk through all the moves she remembers without any problem.
2. There is no empty cell inside the maze that Alice did not visit.
3. The maze is closed, that is, walls separate the inside of the maze from the outside. Infinity in any direction is regarded as outside the maze, and every empty cell that is not connected to the outside is regarded as inside the maze. (The maze map is four-connected, that is, only up, down, left and right count as connected.)
4. Subject to the first three conditions, the number of walls in the maze should be as small as possible.
Input Format
The first line contains one positive integer $N$, the number of moves Alice remembers.
The next line contains $N$ English characters, only among the four characters `U`, `D`, `L` and `R`, which stand for up, down, left and right respectively.
Output Format
Please output the maze map as a character drawing. The maze map may contain many lines; use the character `*` for a wall and `' '` (a space) for a non-wall.
Your output must satisfy the following conditions:
1. At least one line has `*` as its first character.
2. The first line contains at least one `*`.
Explanation/Hint
**Sample Explanation**
Alice can take the sixth character of the sixth line as the starting point.
:::align{center}
```
OWWWWWO
WIIIIIW
WIWWWIW
WIWWWIW
WIWWWIW
WIIIIIW
OWWWWWO
```
::::
In the diagram, `O` is outside the maze, `W` is a wall and `I` is inside the maze.
**Constraints**
For all test cases, $0 < N \leq 100$.
Translated by QwenWork