Car and 2D Plane
Practice
0 (0 votes)
Implementation
Easy
Math
Problem
64% Success 783 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You have been given a remote controlled car which moves on a 2-D Plane. Initially it is placed on coordinates (0,0) and you are controlling it through a set of one move commands given with string CMD.

There are total 4 one-move operations.

Suppose car is at (X,Y).Then

'U' means the car will move from (X,Y) to (X,Y+1)

'D' means the car will move from (X,Y) to (X,Y-1)

'L' means the car will move from (X,Y) to (X-1,Y)

'R' means the car will move from (X,Y) to (X+1,Y)

The set of commands in the String CMD will be performed from Left to Right and can be repeated infinite times. Now determine the minimum number of times you have to follow CMD so that you can reach the given point (P,Q).

UPDATE

The car will halt after reaching the end point and that iteration of CMD will be counted

INPUT

First line of each test file contains T which is the number of test cases.

The next line will contain two space separated integers P and Q followed by string CMD in the next line.

OUTPUT

Print YES followed by the minimum number of times CMD has to be followed so that the car can reach point P and Q ,separated with space. If it is not possible to reach P and Q then print simply print NO.

CONSTRAINTS

1 <= T <= 5

-10^9 <= P <= 10^9

-10^9 <= Q <= 10^9

1<=|CMD|<=100

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
17 votes
Tags:
MathematicsBasic MathModular arithmeticMath
Points:20
11 votes
Tags:
Basic ProgrammingOpenApprovedEasyMathamatics
Points:20
173 votes
Tags:
Ad-HocMathematicsOpenApprovedEasyMathamatics