301692: CF321A. Ciel and Robot

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Ciel and Robot

题意翻译

- 你现在在一个迷宫的 $(0,0)$ 处,给定一个包含 $\texttt{U,D,L,R}$ 的操作序列 $s$,其中 $\texttt{U}$ 表示向上走一格,$\texttt{D}$ 表示向下走一格,$\texttt{L}$ 表示向左走一格,$\texttt{R}$ 表示向右走一格。你将会按照 $s$ 从左往右的操作移动,并且重复若干次。问你是否能够到达 $(a,b)$ 处。 - $-10^9\leqslant a,b\leqslant 10^9$。

题目描述

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) $ → $ (x, y+1); - 'D': go down, (x, y) $ → $ (x, y-1); - 'L': go left, (x, y) $ → $ (x-1, y); - 'R': go right, (x, y) $ → $ (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) $ .

输入输出格式

输入格式


The first line contains two integers $ a $ and $ b $ , ( $ -10^{9}<=a,b<=10^{9} $ ). The second line contains a string $ s $ ( $ 1<=|s|<=100 $ , $ s $ only contains characters 'U', 'D', 'L', 'R') — the command.

输出格式


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

输入输出样例

输入样例 #1

2 2
RU

输出样例 #1

Yes

输入样例 #2

1 2
RU

输出样例 #2

No

输入样例 #3

-1 1000000000
LRRLU

输出样例 #3

Yes

输入样例 #4

0 0
D

输出样例 #4

Yes

说明

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) $ → $ (1, 0) $ → $ (1, 1) $ → $ (2, 1) $ → $ (2, 2) $ → $ $ ... $ So it can reach (2, 2) but not (1, 2).

Input

题意翻译

- 你现在在一个迷宫的 $(0,0)$ 处,给定一个包含 $\texttt{U,D,L,R}$ 的操作序列 $s$,其中 $\texttt{U}$ 表示向上走一格,$\texttt{D}$ 表示向下走一格,$\texttt{L}$ 表示向左走一格,$\texttt{R}$ 表示向右走一格。你将会按照 $s$ 从左往右的操作移动,并且重复若干次。问你是否能够到达 $(a,b)$ 处。 - $-10^9\leqslant a,b\leqslant 10^9$。

加入题单

算法标签: