Wards
InterviewTime limit2sMemory limit1024 MB
Given a letter grid split into regions and a move log with ward placements, print which cells Hanbyeol can see.
- Level
Easy3 of 10
- Topics
- BFS, Simulation, Matrix
- Solved
- No attempts yet
Problem
Hanbyeol was hit by an Isekai Chaos Bus on his way to work.

Figure B.1: Isekai Chaos Bus

Figure B.2: Hanbyeol going to work
He used up all of his vacation days this year and needs to get back to Pangyo right away. To find a way home, he decides to explore the isekai.
The isekai is an grid. It is night, so Hanbyeol can see only the cell he is standing on and the cells directly above, below, left, or right of it. Placing a ward lets him see a wider area. Every cell belongs to exactly one region. When a ward is placed, Hanbyeol can see every cell in the region that contains the cell where the ward was placed.
Given Hanbyeol's travel log, compute how much of the isekai he can see.
Input
The first line contains two integers and , the size of the grid. ()
The next lines describe the grid. Each line has lowercase English letters. If two orthogonally adjacent cells have the same letter, they belong to the same region.
The next line contains two integers and , the cell where Hanbyeol fell into the isekai. He landed in row from the top and column from the left. (, )
The last line contains a string of at most characters describing Hanbyeol's travel log. Each character is one of U, D, L, R, or W. U, D, L, and R mean he moved one cell up, down, left, or right. W means he placed a ward on his current cell. The log never takes him outside the grid.
Output
Print lines of characters each, showing Hanbyeol's view. In row , column , print . if that cell is visible to Hanbyeol, and # if it is not.