QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 1024 MB 満点: 100

#23979. JOI 消除器

統計

題目描述

有一個由 J、O、I 組成且長度為 $N$ 的字串 $S$。JOI 君對字串 $S$ 不斷重複以下操作,直到無法再進行操作為止:

  • 在 $S$ 中選擇 $1$ 處按此順序連續排列著 J、O、I 的位置,並將該部分替換為 O、I、J 的排列。

可以證明,操作的重複一定會終止,並且無論如何進行操作,最終的字串狀態都是唯一確定的。

給定初始字串 $S$ 的資訊,請編寫程式求出最終的字串 $S$。

數據範圍

  • $3 \le N \le 500000$。
  • $S$ 是由 J、O、I 組成且長度為 $N$ 的字串。
  • $N$ 是整數。

子任務

  1. ($14$ 分)$N \le 100$。
  2. ($27$ 分)$N$ 是 $3$ 的倍數,且 $S$ 是將 JOI 重複 $N / 3$ 次所得的字串。
  3. ($29$ 分)存在整數 $k$($2 \le k \le N$),使得 $S$ 的第 $1$ 個字元到第 $k$ 個字元全部為 J,而第 $(k + 1)$ 個及之後的字元均不為 J。
  4. ($30$ 分)無額外約束。

輸入格式

輸入透過標準輸入以如下格式給出:

N
S

輸出格式

在標準輸出中以 $1$ 行輸出最終的字串 $S$。

範例

範例輸入 1

6
JOIJOI

範例輸出 1

OIOIJJ

例如,JOI 君可以按如下方式進行操作。

最初,$S =$ JOIJOI。

  1. 對第 $1$ 個字元到第 $3$ 個字元進行操作,得到 $S =$ OIJJOI。
  2. 對第 $4$ 個字元到第 $6$ 個字元進行操作,得到 $S =$ OIJOIJ。
  3. 對第 $3$ 個字元到第 $5$ 個字元進行操作,得到 $S =$ OIOIJJ。

由於無法再進行操作,輸出 OIOIJJ。

本範例輸入滿足子任務 $1, 2, 4$ 的限制。


範例輸入 2

8
JJJOIOIO

範例輸出 2

OIOIJJJO

本範例輸入滿足子任務 $1, 3, 4$ 的限制。


範例輸入 3

20
JJOIJOIJOOIJOIIJJOIO

範例輸出 3

OIOIJJJJOOIOIJIOIJJO

本範例輸入滿足子任務 $1, 4$ 的限制。

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.