Problem E
Railway Runner
Mario decided to outsmart the coolest game of all time
“Railway Runner”. But as always he needs your help. Given a
railway pattern, he wants to figure out if it is possible to
get from one end to the other. Input is given in
-
You can move left and right between two trains (“*”) or two rails (“.”) that are adjacent to each other, but you cannot go backward (up). No diagonal moves are allowed.
-
You can only get on a train from an adjacent train or via a ladder (“/”).
-
You can jump down on the rails from a train rooftop without hurting yourself. You cannot jump off the train to an adjacent line.
-
Assume the input is valid (i.e. each ladder is followed by a train and preceded by a rail).
-
You can start on any column in the first row as long as it’s a rail (“.”). You can finish on any column in the last row without further restrictions.
-
While on a ladder, you must move forward to the corresponding train roof and climb the ladder.
![\includegraphics[width=0.8\textwidth ]{railway.jpeg}](/problems/railwayrunner/file/statement/en/img-0001.jpeg)
Input
The first line of input contains a single integer
Then follows
Output
Output one line containing either string “YES” or “NO”, depending on if you can reach the other side of the railway.
Sample Input 1 | Sample Output 1 |
---|---|
10 *.* *.. **/ ..* .** .** /** *** *.. .** |
YES |
Sample Input 2 | Sample Output 2 |
---|---|
16 ... /// *** ... *.* ./. .*. .*. .*. .*. .*. /./ *** *** *** ... |
NO |