#R265C. [ABC265C] Belt Conveyor
[ABC265C] Belt Conveyor
Score : points
Problem Statement
We have a grid with horizontal rows and vertical columns. denotes the square at the -th row from the top and -th column from the left.
has a character written on it. is U, D, L, or R.
You are initially at . You repeat the following operation until you cannot make a move.
Let be the square you are currently at. If is
Uand , move to . If isDand , move to . If isLand , move to . If isRand , move to . Otherwise, you cannot make a move.Print the square you end up at when you cannot make a move. If you indefinitely repeat moving, print
-1instead.
Constraints
- is
U,D,L, orR. - and are integers.
Input
Input is given from Standard Input in the following format:
Output
If you end up at , print it in the following format:
If you indefinitely repeat moving, print -1.
2 3
RDU
LRU
1 3
You will move as , ending up here, so the answer is .
2 3
RRD
ULL
-1
You will indefinitely repeat moving as $(1, 1) \to (1, 2) \to (1, 3) \to (2, 3) \to (2, 2) \to (2, 1) \to (1, 1) \to (1, 2) \to \dots$, so -1 should be printed in this case.
9 44
RRDDDDRRRDDDRRRRRRDDDRDDDDRDDRDDDDDDRRDRRRRR
RRRDLRDRDLLLLRDRRLLLDDRDLLLRDDDLLLDRRLLLLLDD
DRDLRLDRDLRDRLDRLRDDLDDLRDRLDRLDDRLRRLRRRDRR
DDLRRDLDDLDDRLDDLDRDDRDDDDRLRRLRDDRRRLDRDRDD
RDLRRDLRDLLLLRRDLRDRRDRRRDLRDDLLLLDDDLLLLRDR
RDLLLLLRDLRDRLDDLDDRDRRDRLDRRRLDDDLDDDRDDLDR
RDLRRDLDDLRDRLRDLDDDLDDRLDRDRDLDRDLDDLRRDLRR
RDLDRRLDRLLLLDRDRLLLRDDLLLLLRDRLLLRRRRLLLDDR
RRRRDRDDRRRDDRDDDRRRDRDRDRDRRRRRRDDDRDDDDRRR
9 5