#abc221g. G - Jumping sequence
G - Jumping sequence
Score : points
问题描述
考虑一个无限的二维坐标平面。Takahashi 初始时位于点 ,他将进行 次跳跃,每次从四个方向(上、下、左、右)中选择一个方向进行跳跃。每次跳跃的距离是固定的。具体来说,第 次跳跃应覆盖距离 。判断在经过 次跳跃后,是否可能精确地到达点 。如果可能,请展示一种实现的方法。
这里,对于每个方向,从点 出发,长度为 的跳跃会将他带到以下点:
- 向上:
- 向下:
- 向左:
- 向右:。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Consider an infinite two-dimensional coordinate plane. Takahashi, who is initially standing at , will do jumps in one of the four directions he chooses every time: up, down, left, or right. The length of each jump is fixed. Specifically, the -th jump should cover the distance of . Determine whether it is possible to be exactly at after jumps. If it is possible, show one way to do so.
Here, for each direction, a jump of length from takes him to the following point:
- up:
- down:
- left:
- right: .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
In the first line, print Yes
if there is a desired sequence of jumps, and No
otherwise.
In the case of Yes
, print in the second line a desired sequence of jumps as a string of length consisting of U
, D
, L
, R
, as follows:
- if the -th jump is upward, the -th character should be
U
; - if the -th jump is downward, the -th character should be
D
; - if the -th jump is to the left, the -th character should be
L
; - if the -th jump is to the right, the -th character should be
R
.
Sample Input 1
3 2 -2
1 2 3
Sample Output 1
Yes
LDR
If he jumps left, down, right in this order, Takahashi moves and ends up at , which is desired.
Sample Input 2
2 1 0
1 6
Sample Output 2
No
It is impossible to be exactly at after the two jumps.
Sample Input 3
5 6 7
1 3 5 7 9
Sample Output 3
Yes
LRLUR
update @ 2024/3/10 09:45:50