No.3183 Swap or Rotate
Problem Statement
You are given a permutation $P = (P_0, P_1, \cdots, P_{N - 1})$ of $(0, 1, 2, \cdots, N - 1)$.
Your goal is to make $P = (0, 1, 2, \cdots, N - 1)$. To do so, you may perform the following $2$ operations in any order, up to $20000$ times.
- Swap $P_0$ and $P_1$.
- For $i = 0, 1, \cdots, N - 1$, simultaneously replace $P_i$ with $P_{(i + 1) \ \mathrm{mod} \ N}$.
Input
$N$
$P_0 \ P_1 \ \cdots P_{N - 1}$
- $3 \leq N \leq 100$
- $P$ is a permutation of $(0, 1, 2, \cdots, N - 1)$
- All inputs are integers
Output
If the goal can be achieved with $M$ operations, output a string of $M$ characters. The $i$-th character should be S if the $i$-th operation swaps $P_0$ and $P_1$, and R otherwise.
If there are multiple valid sequences of operations, you may output any of them.
Sample
Sample 1
Input
4
3 1 0 2
Output
SSRS
- After the $1$st operation, $P = (1, 3, 0, 2)$.
- After the $2$nd operation, $P = (3, 1, 0, 2)$.
- After the $3$rd operation, $P = (1, 0, 2, 3)$.
- After the $4$th operation, $P = (0, 1, 2, 3)$.
Sample 2
Input
3
0 1 2
Output
If the goal is already achieved without any operations, you may output an empty string.
Sample 3
Input
3
2 1 0
Output
SRR
Outputs such as RS are also accepted as correct.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
蜜蜂