0% found this document useful (0 votes)
14 views

ProblemStatement_2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

ProblemStatement_2

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Robot on the grid.

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.

Your task is to find out the final coordinates of the robot.


Note: There is a possibility that the robot falls out of the grid anytime between execution of
moves. The further moves will not be executed if the robot falls out of the grid.

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​ <= 10​5
● 1 <=​ x, y​ <= n
● 1 <= ​S​ <= 10​3
- 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.

You might also like