CF1327C.Game with Chips

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Petya has a rectangular Board of size n×mn \times m. Initially, kk chips are placed on the board, ii-th chip is located in the cell at the intersection of sxisx_i-th row and syisy_i-th column.

In one action, Petya can move all the chips to the left, right, down or up by 11 cell.

If the chip was in the (x,y)(x, y) cell, then after the operation:

  • left, its coordinates will be (x,y−1)(x, y - 1);
  • right, its coordinates will be (x,y+1)(x, y + 1);
  • down, its coordinates will be (x+1,y)(x + 1, y);
  • up, its coordinates will be (x−1,y)(x - 1, y).

If the chip is located by the wall of the board, and the action chosen by Petya moves it towards the wall, then the chip remains in its current position.

Note that several chips can be located in the same cell.

For each chip, Petya chose the position which it should visit. Note that it's not necessary for a chip to end up in this position.

Since Petya does not have a lot of free time, he is ready to do no more than 2nm2nm actions.

You have to find out what actions Petya should do so that each chip visits the position that Petya selected for it at least once. Or determine that it is not possible to do this in 2nm2nm actions.

佩佳有一个大小为 n×mn \times m 的矩形棋盘。初始时,棋盘上放置了 kk 个芯片,其中第 ii 个芯片位于第 sxisx_i 行与第 syisy_i 列相交的格子中。

在一次操作中,佩佳可以将所有芯片同时向左、向右、向下或向上移动 1 格。

若某芯片当前位于 (x,y)(x, y) 格,则执行操作后其坐标变为:

  • 向左:(x,y−1)(x, y - 1);
  • 向右:(x,y+1)(x, y + 1);
  • 向下:(x+1,y)(x + 1, y);
  • 向上:(x−1,y)(x - 1, y)。

若某芯片已位于棋盘边界上,而佩佳选择的操作方向会使其撞向边界,则该芯片保持原位不动。

注意:多个芯片可以位于同一格子中。

对于每个芯片,佩佳都指定了一个它必须至少访问一次的目标位置(注意:芯片最终不必停留在该位置)。

由于佩佳空闲时间有限,他最多只愿执行 2nm2nm 次操作。

你需要找出一组操作序列(长度不超过 2nm2nm),使得每个芯片都至少一次到达佩佳为其指定的目标位置;或者判断在 2nm2nm 次操作内无法实现这一目标。

输入格式

The first line contains three integers n,m,kn, m, k (1≤n,m,k≤2001 \le n, m, k \le 200) — the number of rows and columns of the board and the number of chips, respectively.

The next kk lines contains two integers each sxi,syisx_i, sy_i ($ 1 \le sx_i \le n, 1 \le sy_i \le m$) — the starting position of the ii-th chip.

The next kk lines contains two integers each fxi,fyifx_i, fy_i ($ 1 \le fx_i \le n, 1 \le fy_i \le m$) — the position that the ii-chip should visit at least once.

第一行包含三个整数 n,m,kn, m, k(1≤n,m,k≤2001 \le n, m, k \le 200),分别表示棋盘的行数、列数以及芯片的数量。

接下来的 kk 行,每行包含两个整数 sxi,syisx_i, sy_i(1≤sxi≤n, 1≤syi≤m1 \le sx_i \le n,\ 1 \le sy_i \le m)——表示第 ii 个芯片的起始位置。

再接下来的 kk 行,每行包含两个整数 fxi,fyifx_i, fy_i(1≤fxi≤n, 1≤fyi≤m1 \le fx_i \le n,\ 1 \le fy_i \le m)——表示第 ii 个芯片至少需要访问一次的目标位置。

输出格式

In the first line print the number of operations so that each chip visits the position that Petya selected for it at least once.

In the second line output the sequence of operations. To indicate operations left, right, down, and up, use the characters L,R,D,UL, R, D, U respectively.

If the required sequence does not exist, print -1 in the single line.

第一行输出操作次数,使得每个芯片至少访问一次佩蒂亚为其指定的位置。

第二行输出操作序列。使用字符 LL、RR、DD、UU 分别表示向左、向右、向下、向上操作。

如果不存在满足要求的操作序列,则在单独一行中输出 −1-1。

输入输出样例

  • 输入#1

    3 3 2
    1 2
    2 1
    3 3
    3 2

    输出#1

    3
    DRD
  • 输入#2

    5 4 3
    3 4
    3 1
    3 3
    5 3
    1 3
    1 4

    输出#2

    9
    DDLUUUURR

输入解题思路,AI测评打分。不知道怎么写?

首页