ProblemStatement_2
ProblemStatement_2
A remote controlled robot is placed on an n*n square grid which is floating above the
floor. Rows on the grid are numbered through 1...n from top and columns are numbered 1
to n from left. The robot moves in four directions, i.e. North(N), East(E), South(S) and
West(W).
You are given the initial coordinates of the robot and all the moves of it. Moves are
represented in format ->
“D S“ i.e. {direction_code space num_of_steps}
D ⋳ {N, E, S, W} S is an integer.
INPUT :
- The first line of input consists of n, the size of grid.
- The second line of input consists of two space separated integers, x and y, denoting
the initial coordinates of the robot.
- The third line consists of an integer m, denoting the number of moves to be
performed by robot.
- Following m l ines have two space separated char and integer, D and S, denoting
type of moves.
OUTPUT :
- Output consists of only one line. Print the final coordinates of the robot separated by
space. If the robot falls out of the grid, print “FALL” without quotes.
CONSTRAINTS :
● 1 <= n <= 105
● 1 <= x, y <= n
● 1 <= S <= 103
- Time limit per test = 2 sec
- Memory Limit = 256 MBytes
- I/O = Standard I/O
SAMPLE INPUT :
- Test #1
10
55
3
N3
E4
S7
- Test #2
5
11
3
S3
W2
E3
SAMPLE OUTPUT :
- Test #1
99
- Test #2
FALL
EXPLANATION:
-Test #1 results in (9 9) because all the moves were valid and the robot ended up on
the grid.
-Test #2 results in FALL because the falls down the grid after executing the 2nd
move and hence further moves were dismissed.