3558.Ciel and Robot

Time Limit: 1s Memory Limit: 256MB

Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string s. Each character of s is one move operation. There are four move operations at all:
'U': go up, (x, y) \rightarrow (x, y+1); 'D': go down, (x, y) \rightarrow (x, y-1); 'L': go left, (x, y) \rightarrow (x-1, y); 'R': go right, (x, y) \rightarrow (x+1, y).
The robot will do the operations in s from left to right, and repeat it infinite times. Help Fox Ciel to determine if after some steps the robot will located in (a,b).

Input Format(From the terminal/stdin)

The first line contains two integers a and b, (-109 \le a,b \le 109). The second line contains a string s (1 \le |s| \le 100, s only contains characters 'U', 'D', 'L', 'R') - the command.

Output Format(To the terminal/stdout)

Print "Yes" if the robot will be located at (a,b), and "No" otherwise.

Sample Input 1

Copy
2 2
RU
 · \n
  \n

Sample Output 1

Copy
Yes
   \n

Sample Input 2

Copy
1 2
RU
 · \n
  \n

Sample Output 2

Copy
No
  \n

Sample Input 3

Copy
-1 1000000000
LRRLU
  ·          \n
     \n

Sample Output 3

Copy
Yes
   \n

Sample Input 4

Copy
0 0
D
 · \n
 \n

Sample Output 4

Copy
Yes
   \n

Hints

In the first and second test case, command string is "RU", so the robot will go right, then go up, then right, and then up and so on.

The locations of its moves are (0, 0) \rightarrow (1, 0) \rightarrow (1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow ...

So it can reach (2, 2) but not (1, 2).

Submit

请先 登录

© 2025 FAQs