QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 100

#23817. JJOOII

Statistics

題目描述

為咗備戰 JOI 本選而練習編程嘅你,留意到今年嘅 JOI 預選淨係得數值題而冇字串題。於是,你決定偷偷地提升自己喺字串題方面嘅實力,同競爭對手拉開距離。睇返過去嘅 JOI 題目之後,你發現應該先熟習由 J、O、I 呢 $3$ 種字元組成嘅字串。等我哋嚟考慮呢類字串。你諗出咗「回答給定嘅字串係咪包含 JOI 作為子字串」呢個問題,並即刻解決咗佢。想解決更高水平問題嘅你,創作咗下面呢道題目。

如果透過喺字串 $t$ 嘅開頭同埋結尾加上若干個字元(亦可以係 $0$ 個字元)能夠得到字串 $s$,就稱 $t$ 係字串 $s$ 嘅子字串。例如,JJOOII 係 OJJOOIIOJOI 嘅子字串。另一方面,JOI 唔係 JOOI 嘅子字串。

另外,對於大於或等於 $0$ 嘅整數 $k$,由 $k$ 個字元 J、$k$ 個字元 O、$k$ 個字元 I 按呢個順序排列而成嘅字串稱為等級 $k$ 嘅 JOI 串。例如,JJOOII 係等級 $2$ 嘅 JOI 串。

我哋想喺作為給定字串嘅子字串嘅 JOI 串入面,搵出等級最大嘅一個。

任務

給定由 J、O、I 呢 $3$ 種字元組成、長度為 $N$ 嘅字串 $S$,請編寫一個程式,求出令到等級 $k$ 嘅 JOI 串係 $S$ 嘅子字串嘅 $k$ 嘅最大值。

限制

  • $1 \le N \le 1000000 \ (= 10^6)$:$S$ 嘅長度。

輸入格式

從標準輸入讀取以下數據。

  • 第 $1$ 行寫有一個由 J、O、I 呢 $3$ 種字元組成嘅字串 $S$。

輸出格式

向標準輸出輸出 $1$ 行,表示令到等級 $k$ 嘅 JOI 串係 $S$ 嘅子字串嘅 $k$ 嘅最大值嘅整數。

子任務

  • 喺佔總分 $20\%$ 嘅評測數據入面,滿足 $N \le 100$。

樣例 1

輸入

OJJOOIIOJOI

輸出

2

OJJOOIIOJOI 包含作為等級 $2$ 嘅 JOI 串嘅 JJOOII 作為子字串,而且唔包含等級 $3$ 或以上嘅 JOI 串作為子字串。

樣例 2

輸入

IJJIIJJJ

輸出

0

等級 $0$ 嘅 JOI 串係長度為 $0$ 嘅字串。

樣例 3

輸入

JOIJOIJOIJOIJOI

輸出

1

樣例 4

輸入

OOJJJJJJOOOOIIIII

輸出

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.