#abc221g. G - Jumping sequence

G - Jumping sequence

Score : 600600 points

问题描述

考虑一个无限的二维坐标平面。Takahashi 初始时位于点 (0,0)(0,0),他将进行 NN 次跳跃,每次从四个方向(上、下、左、右)中选择一个方向进行跳跃。每次跳跃的距离是固定的。具体来说,第 ii 次跳跃应覆盖距离 DiD_i。判断在经过 NN 次跳跃后,是否可能精确地到达点 (A,B)(A, B)。如果可能,请展示一种实现的方法。

这里,对于每个方向,从点 (X,Y)(X, Y) 出发,长度为 DD 的跳跃会将他带到以下点:

  • 向上:(X,Y)(X,Y+D)(X,Y) \to (X,Y+D)
  • 向下:(X,Y)(X,YD)(X,Y) \to (X,Y-D)
  • 向左:(X,Y)(XD,Y)(X,Y) \to (X-D,Y)
  • 向右:(X,Y)(X+D,Y)(X,Y) \to (X+D,Y)

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Consider an infinite two-dimensional coordinate plane. Takahashi, who is initially standing at (0,0)(0,0), will do NN 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 ii-th jump should cover the distance of DiD_i. Determine whether it is possible to be exactly at (A,B)(A, B) after NN jumps. If it is possible, show one way to do so.

Here, for each direction, a jump of length DD from (X,Y)(X, Y) takes him to the following point:

  • up: (X,Y)(X,Y+D)(X,Y) \to (X,Y+D)
  • down: (X,Y)(X,YD)(X,Y) \to (X,Y-D)
  • left: (X,Y)(XD,Y)(X,Y) \to (X-D,Y)
  • right: (X,Y)(X+D,Y)(X,Y) \to (X+D,Y).

Constraints

  • 1N20001 \leq N \leq 2000
  • A,B3.6×106\lvert A\rvert, \lvert B\rvert \leq 3.6\times 10^6
  • 1Di18001 \leq D_i \leq 1800
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN AA BB

D1D_1 D2D_2 \ldots DND_N

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 SS of length NN consisting of U , D , L , R, as follows:

  • if the ii-th jump is upward, the ii-th character should be U;
  • if the ii-th jump is downward, the ii-th character should be D;
  • if the ii-th jump is to the left, the ii-th character should be L;
  • if the ii-th jump is to the right, the ii-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 (0,0)(1,0)(1,2)(2,2)(0,0)\to(-1,0)\to(-1,-2)\to(2,-2) and ends up at (2,2)(2, -2), which is desired.

Sample Input 2

2 1 0
1 6

Sample Output 2

No

It is impossible to be exactly at (1,0)(1, 0) 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