Maze Ball Game

cosmicray001 16th December Programming...
Limits 1s, 512 MB

Your friend Yulianna Karaulova, likes to play maze ball game. You are going make a DIY project to build a maze ball game. Making maze game is very easy. Generally there is a maze and some holes might be in the maze(the exit point). There is a ball inside the maze that can move left, right, top and bottom depending on which side of the maze is lower because of gravity. Once a ball fell in a hole, it will never comes out regardless of the tilt position.
In this problem, there will be some moves and your task is to tell whether the player will be able to put the ball inside the hole.


The input begins with two positive integers R, C (1 < R, C ≤ 100). Here R denotes the row and C denotes the column of the maze. Next each R line, there will be C characters. The characters can be either ‘ ’ ( space denotes safe to go) or ‘*’ ( asterisk denotes obstacle, can’t go there) or ‘O’ ( 'O' denotes the hole which is the exit point). After that there will be two numbers A, B (1 ≤ A ≤ R and 1 ≤ B ≤ C). A denotes the row and B denotes the column which is the initial position of the ball and a string S (each character of the string denotes the move which will be given by a player and length of the string is not more than 10000). The moves are either ‘L’ (left side is down) or ‘R’(right side is down) or ‘T’(top side is down) or ‘B’(bottom side is down). When one side is down the ball roll down and stops when founds obstacle ‘*’ or gets out of the maze if founds a hole ‘O’.
Note: The maze is surrounded by '*'. Initial position of the ball is not on an obstacle.


Print ‘YES’ or ‘NO’ (without quotes) depending on the result.


5 4
*O *
* **
4 2
8 8
*O     *
****** *
*      *
* ******
*      *
*      *
7 2


Login to submit.


90% Solution Ratio
PrimeXEarliest, Dec '19
s_dasailorFastest, 0.0s
PrimeXLightest, 131 kB
habijabiShortest, 934B
Toph uses cookies. By continuing you agree to our Cookie Policy.