QOJ.ac

QOJ

Limite de temps : 2.0 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#10726. 弄巧成拙

Statistiques

陈教授开发了一种新型机器人,名为:Speedy Universal Guided Assistance Robot(高速通用引导辅助机器人)。为了测试这种新机器人能否为 Pigeland 的居民提供稳定的服务,陈教授准备了一项测试。

测试场地由一条从左到右延伸的水平跑道组成,包含 $n + 1$ 个位置,标记为 $0, 1, 2, \dots, n$。陈教授可以向机器人发出以下指令:

  • 向左移动(Move Left):假设机器人当前位于位置 $x$ ($x > 0$)。执行此指令后,机器人将移动到 $x - 1$。机器人在位置 $0$ 时无法执行此指令。
  • 向右移动(Move Right):假设机器人当前位于位置 $x$ ($x < n$)。执行此指令后,机器人将移动到 $x + 1$。机器人在位置 $n$ 时无法执行此指令。

测试开始时,机器人位于位置 $0$;测试结束时,机器人也必须回到位置 $0$。陈教授要求机器人在执行移动操作后(不包括初始位置),必须恰好到达位置 $i$ 共 $c_i$ 次。现在,陈教授请你设计一个长度为 $\sum_{i=0}^{n} c_i$ 的操作序列,由字符 L 和 R 组成(其中 L 代表向左移动,R 代表向右移动),使得机器人按顺序执行该测试序列中的操作能够满足上述要求。如果存在多个合法的序列,陈教授希望你找到字典序最小的一个。如果不存在这样的序列,你应该报告这一点。

†:对于长度为 $m$ 的字符串 $s$ 和 $t$,若存在 $1 \le i \le m$,使得对于所有 $j < i$ 都有 $s_j = t_j$,且 $s_i < t_i$,则称 $s$ 的字典序小于 $t$。在字典序比较中,我们定义 “L” 的字典序小于 “R”。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$ ($1 \le T \le 10^5$),表示测试数据的组数。

对于每组测试数据,第一行包含一个整数 $n$ ($1 \le n \le 5 \cdot 10^5$)。

第二行包含 $n + 1$ 个整数,第 $i$ 个整数为 $c_{i-1}$ ($1 \le c_{i-1} \le 10^6$)。

保证所有测试数据的 $n$ 之和不超过 $5 \cdot 10^5$,且所有测试数据的 $\sum_{i=0}^{n} c_i$ 之和不超过 $2 \cdot 10^6$。

输出格式

对于每组测试数据,如果存在合法的测试序列,请输出一个长度为 $\sum_{i=0}^{n} c_i$ 的字符串,仅包含字符 L 和 R,占一行。否则,输出 “Impossible” 占一行,表示不存在这样的序列。

样例

输入 1

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

输出 1

RLRRLL
RRRRRLLLLL
Impossible

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.