eolymp
bolt
Try our new interface for solving problems
Məsələlər

Mysterious Maze

Mysterious Maze

A robot in a two-dimensional maze again. The maze has an entrance and an exit this time, though. Just as in the previous problem, the maze is made up of \textbf{H}×\textbf{W} grid cells, its upper side faces north, and each cell is either empty or wall. Unlike the previous, on the other hand, one of the empty cells is connected to the entrance and another to the exit. The robot is rather complex | there is some control, but not full. It is associated with a controller that has two buttons, namely \textit{forward} and \textit{turn}. The forward button moves the robot forward to the next cell, if possible. The robot can not move into a wall nor outside the maze. The turn button turns the robot as \textit{programmed}. Here the program is a nite sequence of N commands, each of which is either '\textbf{L}' (indicating a left turn) or '\textbf{R}' (a right turn). The first turn follows the rst command; the second turn follows the second command; similar for the following turns. The turn button stops working once the commands are exhausted; the forward button still works in such a case though. The robot always turns by \textbf{90} degrees at once. The robot is initially put on the entrance cell, directed to the north. Your mission is to determine whether it can reach the exit cell if controlled properly. \InputFile The input is a sequence of datasets. Each dataset is formatted as follows. \textbf{H W N s_1 ... s_N c_\{1,1\}c_\{1,2\} ... c_\{1,W\} ... c_\{H,1\}c_\{H,2\} ... c_\{H,W\}} The fi rst line of a dataset contains three integers \textbf{H}, \textbf{W} and \textbf{N} (\textbf{1} ≤ \textbf{H}, \textbf{W} ≤ \textbf{1000}, \textbf{1} ≤ \textbf{N} ≤ \textbf{1000000}). The second line contains a program of \textbf{N} commands. Each of the following \textbf{H} lines contains exactly \textbf{W} characters. Each of these characters represents a cell of the maze. "\textbf{.}" indicates empty, "\textbf{#}" indicates a wall, "\textbf{S}" indicates an entrance, and "\textbf{G}" indicates an exit. There is exactly one entrance cell and one exit cell. The end of input is indicated by a line with three zeros. \OutputFile For each dataset, output whether the robot can reach the exit in a line: "\textbf{Yes}" if it can or "\textbf{No}" otherwise (without quotes).
Zaman məhdudiyyəti 30 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB
Giriş verilənləri #1
2 2 1
L
G.
#S
2 2 2
RR
G.
.S
3 3 6
LLLLLL
G#.
...
.#S
0 0 0
Çıxış verilənləri #1
Yes
No
Yes
Mənbə ACM International Collegiate Programming Contest JAG Practice Contest, Tokyo, 2011-11-06