QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#17957. RPS 冒泡排序

統計

Yihwan 是一个喜欢玩石头剪刀布的 5 岁天才。他想在家里一个人玩石头剪刀布,于是他发挥创意,用一些卡牌设计了一个游戏。

Yihwan 在位置 $1, 2, \dots, N$ 上放置了 $N$ 张卡牌,每张卡牌上写着剪刀、石头或布中的一种。然后,对于按升序排列的每个 $i = 1, 2, \dots, N - 1$,如果第 $i$ 个位置的卡牌战胜了第 $i + 1$ 个位置的卡牌,Yihwan 就会交换这两个位置的卡牌。由于游戏的过程类似于冒泡排序,Yihwan 将这个游戏命名为“石头剪刀布冒泡排序”。卡牌之间的胜负关系如下:

  • 剪刀牌战胜布牌。
  • 布牌战胜石头牌。
  • 石头牌战胜剪刀牌。

Yihwan 非常擅长计算,所以他进行了 $T$ 次该游戏过程,然后去睡觉了。然而,在 Yihwan 睡觉时,卡牌不小心被弄乱了。幸运的是,由于 Yihwan 是一个记忆力超群的天才,他记起了游戏开始前初始卡牌的排列顺序。但是,他记不起进行 $T$ 次游戏过程后卡牌的最终排列顺序,现在需要你的帮助。

请通过还原进行 $T$ 次游戏过程后卡牌的最终排列顺序来帮助 Yihwan。

输入格式

第一行包含两个整数,分别表示卡牌的数量 $N$($2 \le N \le 500\,000$)和 Yihwan 进行游戏过程的次数 $T$($1 \le T \le 1\,000\,000\,000$)。

第二行包含一个长度为 $N$ 的字符串。第 $i$ 个字符表示放置在第 $i$ 个位置的卡牌类型。石头牌用 R 表示,剪刀牌用 S 表示,布牌用 P 表示。

输出格式

输出一个长度为 $N$ 的字符串,表示进行 $T$ 次游戏过程后卡牌的最终排列。

样例

输入样例 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.