QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 256 MB Puntuación total: 100

#14757. 太空漫游者

Estadísticas

注意:在本题中,您的程序被系统评测后,您将立即得知提交的得分。

由于本题的特殊性,禁止在论坛板块分享本题的测试数据。不过,您可以在 https://oi.edu.pl/l/33oi_laz 找到一个可以可视化您解决方案的工具。

Bajtazar 刚刚发现了一颗环面(torus)形状的行星。行星表面被一个矩形网格划分为 $n$ 行和 $m$ 列。行从 $0$ 到 $n - 1$ 编号,列从 $0$ 到 $m - 1$ 编号。坐标为 $(x, y)$ 的格子位于第 $x$ 行第 $y$ 列。

为了探索这颗行星,将向那里发送一个太空探测器。它将从坐标为 $(0, 0)$ 的格子开始工作,并根据一系列指令在行星上移动。探测器能识别 4 种类型的指令,分别对应以下移动:

  • G – 从 $(x, y)$ 移动到 $((x - 1) \bmod n, y)$
  • D – 从 $(x, y)$ 移动到 $((x + 1) \bmod n, y)$
  • L – 从 $(x, y)$ 移动到 $(x, (y - 1) \bmod m)$
  • P – 从 $(x, y)$ 移动到 $(x, (y + 1) \bmod m)$

探测器将无限循环地执行这一系列指令:在执行完最后一条指令后,它会重新从头开始执行整个序列。请记住,行星是环面形状的,例如,如果探测器当前位于格子 $(x, 0)$ 并执行移动 L,它将移动到格子 $(x, m - 1)$。

Bajtazar 希望探测器最终能访问行星上的所有 $nm$ 个格子。请帮他设计一个较短的(但不一定是绝对最短的)指令序列来保证这一点。

注意,探测器在行驶过程中多次访问同一个格子是允许的。

输入格式

输入的第一行,也是唯一的一行,包含两个整数 $n$ 和 $m$($2 \le n, m \le 10^6$),分别表示行星表面划分的行数和列数。

输出格式

输出的第一行应包含一个正整数 $k$,表示指令序列的长度。

第二行应包含一个长度为 $k$ 的字符串,由字母 GDLP 组成。

样例

输入样例 1

2 3

输出样例 1

3
DPD

说明 1

样例解释:探测器依次访问以下格子:

$$(0, 0) \xrightarrow{D} (1, 0) \xrightarrow{P} (1, 1) \xrightarrow{D} (0, 1) \xrightarrow{D} (1, 1) \xrightarrow{P} (1, 2) \xrightarrow{D} (0, 2) \xrightarrow{D} (1, 2) \xrightarrow{P} (1, 0) \xrightarrow{D} (0, 0) \xrightarrow{D} \dots$$

其他样例测试:测试 0a 即为上述样例。此外:

  • 0b:$n = 5, m = 4$;指令序列 PPPDDDLLGPGLLDDDPPP 可以访问网格中的所有格子。
  • 0c:$n = 1000, m = 1000$;指令序列 (DP)^{1234567} GGL 可以访问网格中的所有格子。

子任务

测试点分为以下子任务。每个子任务的测试由一个或多个独立的测试组组成。

子任务 限制 分数
1 $n, m \le 6$ 11
2 $n, m \le 20$ 20
3 $n \le 10^3, n = 2m + 3$ 13
4 $n \le 10^3, m \le 20$ 12
5 $n, m \le 10^3$ 24
6 $n, m \le 10^4$ 7
7 $n, m \le 10^5$ 7
8 无附加限制 6

设 $k$ 为你输出的指令序列长度,而 $OPT$ 为最短的可能合法指令序列长度。如果你的指令序列是正确的,那么你的解决方案在给定的测试点上将根据以下公式获得分数:

$$\left\lfloor \frac{100}{\sqrt{1 + k - OPT}} \right\rfloor$$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.