QOJ.ac

QOJ

Süre Sınırı: 2 s Bellek Sınırı: 256 MB Toplam puan: 100

#23865. 圈叉印仔

İstatistikler

題目描述

JOI 君擁有圓圈印仔、叉號印仔同埋圈叉印仔呢 $3$ 種印仔各 $0$ 個或者更多個。呢啲印仔可以喺紙上面印出圓圈或者叉號標記。

用圓圈印仔可以印出 $1$ 個圓圈,用叉號印仔可以印出 $1$ 個叉號。用圈叉印仔可以打橫並排印出圓圈同叉號各 $1$ 個;透過改變印仔嘅方向,既可以令叉號印喺圓圈嘅右邊,亦可以令圓圈印喺叉號嘅右邊。

JOI 君將自己擁有嘅每個印仔按適當嘅順序恰好各用咗 $1$ 次,喺紙上面打橫印出一行圓圈同叉號。印出嘅圓圈同叉號序列用字符串 $S$ 代表。$S$ 係由 O 同 X 組成嘅長度為 $N$ 嘅字符串;如果 $S_i = $ O,就代表 JOI 君印出嘅標記之中由左面數起第 $i$ 個係圓圈,如果 $S_i =$ X,就代表佢係叉號($1 \le i \le N$)。

你唔知道 JOI 君擁有嘅印仔數量,但係知道 JOI 君印出嘅圓圈同叉號序列。請根據印出嘅圓圈同叉號序列,計出 JOI 君可能擁有嘅圈叉印仔數量嘅最大值。

約束條件

  • $1 \le N \le 100000 (= 10^5)$
  • $S$ 係長度為 $N$ 嘅字符串。
  • $S$ 嘅每個字符都係 O 或者 X。

輸入與輸出

輸入
輸入透過標準輸入以以下格式畀出:
$N$
$S$

輸出
輸出 JOI 君可能擁有嘅圈叉印仔數量嘅最大值。

輸入輸出樣例

樣例輸入 1

5
OXXOX

樣例輸出 1

2

JOI 君印出嘅標記由左起依次序係:圓圈、叉號、叉號、圓圈、叉號。如果 JOI 君分別擁有圓圈印仔、叉號印仔、圈叉印仔 $0, 1, 2$ 個,噉按以下順序用印仔,就可以印出噉樣嘅標記:

  • 用第 $1$ 個圈叉印仔,按順序印出圓圈同叉號。
  • 喺佢嘅右邊,用第 $2$ 個圈叉印仔,按順序印出叉號同圓圈。
  • 最後,喺佢嘅右邊,用叉號印仔印出叉號。

由於唔可能擁有 $3$ 個或以上嘅圈叉印仔,因此輸出 $2$。


樣例輸入 2

14
OXOXOXOXXOXOXO

樣例輸出 2

7

樣例輸入 3

10
OOOOOOOOOO

樣例輸出 3

0

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.