QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 1024 MB Points totaux : 100

#23979. JOI 消除器

Statistiques

題目描述

有一個由 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.