QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#17957. じゃんけんバブルソート

统计

Yihwan はじゃんけんが好きな 5 歳の天才です。家で一人でじゃんけんをしたくなったので、創造力を発揮し、カードを使ったゲームを作りました。

Yihwan は位置 $1,2,\ldots,N$ に、それぞれチョキ、グー、パーのいずれかが描かれたカードを合計 $N$ 枚置きます。次に $i=1,2,\ldots,N-1$ の昇順に、位置 $i$ のカードが位置 $i+1$ のカードに勝つなら、それらを交換します。この過程はバブルソートに似ているため、Yihwan はこのゲームを「じゃんけんバブルソート」と名付けました。カードの勝敗関係は以下の通りです。

  • チョキのカードはパーのカードに勝ちます。

  • パーのカードはグーのカードに勝ちます。

  • グーのカードはチョキのカードに勝ちます。

problem_17957_58a3d8a2108c15a99c0b9d48cf0e6e44.png

Yihwan は計算がとても得意なので、このゲームを $T$ 回遊んでから寝ました。しかし寝ている間に、カードが誤って混ぜられてしまいました。幸い、Yihwan は記憶力抜群の天才なので、ゲーム前のカードの初期配置を覚えていました。ただし $T$ 回遊んだ後の最終配置は思い出せず、あなたの助けを必要としています。

ゲームを $T$ 回遊んだ後のカードの最終配置を復元して、Yihwan を助けてください。

入力

最初の行にはカードの枚数 $N$($2\le N\le500\,000$)と Yihwan がゲームを遊んだ回数 $T$($1\le T\le1\,000\,000\,000$)を表す 2 つの整数が含まれます。

2 行目には長さ $N$ の文字列が含まれます。$i$ 文字目は位置 $i$ のカードの種類を表します。グーは R、チョキは S、パーは P です。

出力

ゲームを $T$ 回遊んだ後の長さ $N$ の文字列を出力してください。

入出力例

入力 1

5 1
RSPSP

出力 1

SRPPS

入力 2

10 3
RSRRRRRRSR

出力 2

SRRRRSRRRR

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.