問題一覧 > 通常問題

No.3183 Swap or Rotate

レベル : / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 88
作問者 : 蜜蜂 / テスター : Mitarushi
お気に入りにしたユーザー ProblemId : 12272 / 自分の提出
問題文最終更新日: 2025-06-15 12:53:42
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 471 (順位表) の他の問題:

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}$.
It can be proved that your goal can always be achieved under the constraints. Output one example of a sequence of operations that achieves the goal. Note that you do not need to minimize the number of operations.

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もしくは右上の雲マークをクリックしてアカウントを作成してください。