QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#23865. 圈叉印章

Statistics

题目描述

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.