QOJ.ac

QOJ

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

#4950. 寻找极大非平凡单调序列

統計

在本题中,我们将处理字符序列,通常称为字符串。如果一个序列包含至少两个元素,则称其为非平凡的。

给定一个序列 $s$,如果片段 $s_i, \dots, s_j$ 中的所有字符都相等,则称其为单调的;如果该片段无法向左或向右扩展而不破坏单调性,则称其为极大单调片段。

给定一个仅由字符 “a” 和 “b” 组成的序列,确定有多少个字符 “a” 出现在非平凡的极大单调片段中。

输入格式

输入包含两行。第一行包含一个整数 $N$,其中 $1 \le N \le 10^5$。 第二行包含一个长度恰好为 $N$ 的字符串,仅由字符 “a” 和 “b” 组成。

输出格式

输出一行,包含一个整数,表示字符 “a” 在非平凡极大单调片段中出现的总次数。

样例

样例输入 1

7
abababa

样例输出 1

0

样例输入 2

7
bababab

样例输出 2

0

样例输入 3

10
aababaaabb

样例输出 3

5

样例输入 4

10
bbaababaaa

样例输出 4

5

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.