QOJ.ac

QOJ

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

#23979. JOI Eliminator

統計

Problem Statement

There is a string $S$ of length $N$ consisting of J, O, and I. JOI-kun repeats the following operation on the string $S$ until no more operations can be performed:

  • Choose $1$ place in $S$ where J, O, and I appear contiguously in this order, and replace that part with O, I, and J in this order.

It can be proved that the repetition of operations always terminates, and that the final state of the string is uniquely determined regardless of how the operations are performed.

Given the information of the initial string $S$, write a program to find the final string $S$.

Constraints

  • $3 \le N \le 500000$.
  • $S$ is a string of length $N$ consisting of J, O, and I.
  • $N$ is an integer.

Subtasks

  1. ($14$ points) $N \le 100$.
  2. ($27$ points) $N$ is a multiple of $3$, and $S$ is JOI repeated $N / 3$ times.
  3. ($29$ points) There exists an integer $k$ ($2 \le k \le N$) such that the $1$-st through $k$-th characters of $S$ are all J, while the $(k + 1)$-th and subsequent characters are not J.
  4. ($30$ points) No additional constraints.

Input

The input is given from Standard Input in the following format:

N
S

Output

Print the final string $S$ in $1$ line to Standard Output.

Sample

Sample Input 1

6
JOIJOI

Sample Output 1

OIOIJJ

For example, JOI-kun may perform the operations as follows.

Initially, $S =$ JOIJOI.

  1. Perform the operation on the $1$-st through $3$-rd characters. Then $S =$ OIJJOI.
  2. Perform the operation on the $4$-th through $6$-th characters. Then $S =$ OIJOIJ.
  3. Perform the operation on the $3$-rd through $5$-th characters. Then $S =$ OIOIJJ.

Since no more operations can be performed, print OIOIJJ.

This sample input satisfies the constraints of Subtasks $1, 2, 4$.


Sample Input 2

8
JJJOIOIO

Sample Output 2

OIOIJJJO

This sample input satisfies the constraints of Subtasks $1, 3, 4$.


Sample Input 3

20
JJOIJOIJOOIJOIIJJOIO

Sample Output 3

OIOIJJJJOOIOIJIOIJJO

This sample input satisfies the constraints of Subtasks $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.