#63204. [USACO 2023 Jan Silver]Moo Route

[USACO 2023 Jan Silver]Moo Route

暂无测试数据。

英文题面

Farmer Nhoj dropped Bessie in the middle of nowhere! At time $t=0$, Bessie is located at $x=0$ on an infinite number line. She frantically searches for an exit by moving left or right by $1$ unit each second. However, there actually is no exit and after $T$ seconds, Bessie is back at $x=0$, tired and resigned.

Farmer Nhoj tries to track Bessie but only knows how many times Bessie crosses $x=.5, 1.5, 2.5, \ldots, (N-1).5$, given by an array $A_0,A_1,\dots,A_{N-1}$ ($1\leq N \leq 10^5$, $1 \leq A_i \leq 10^6$, $\sum A_i\le 10^6$). Bessie never reaches $x>N$ nor $x<0$.

In particular, Bessie's route can be represented by a string of $T = \sum_{i=0}^{N-1} A_i$ $L$s and $R$s where the $i$th character represents the direction Bessie moves in during the $i$th second. The number of direction changes is defined as the number of occurrences of $LR$s plus the number of occurrences of $RL$s.

Please help Farmer Nhoj find any route Bessie could have taken that is consistent with $A$ and minimizes the number of direction changes. It is guaranteed that there is at least one valid route.

译文

奶牛 Bessie 开始在一条数轴上原点的位置,每次会向左或向右移动一个单位长度,最后回到了原点。

给定 Bessie 经过 $0.5,1.5,\ldots,(N-1)+0.5$ 的次数(用数组 $A$ 表示,$A_i$ 表示经过 $i+0.5$ 的次数)。

请构造出一条可能的移动路径(由 $\texttt{L}$ 和 $\texttt{R}$ 构成,表示向左 / 向右走),使得中途改变方向的次数尽量少

题目保证有解,若有多解,输出任意一组解即可。

输入格式

The first line contains $N$. The second line contains $A_0,A_1,\dots,A_{N-1}$.

第一行包含 $N$。第二行包含 $A_0,A_1,\dots,A_{N-1}$。

输出格式

Output a string $S$ of length $T = \sum_{i=0}^{N-1} A_i$ where $S_i$ is $L$ or $R$, indicating the direction Bessie travels in during second $i$. If there are multiple routes minimizing the number of direction changes, output any.

输出一个长度为 $T = \sum_{i=0}^{N-1} A_i$ 的字符串 $S$,其中 $S_i$ 为 $L$ 或 $R$,表示第二个 $i$ 中贝西的行进方向。如果有多条路由使方向变化的数量最小化,则输出任意一个即可。

数据范围

Inputs 3-5: $N\leq 2$

Inputs 3-10: $T=A_0+A_1+\cdots +A_{N−1}\leq 5000$

Inputs 11-20: No additional constraints.

2
2 4
RRLRLL
3
2 4 4
RRRLLRRLLL