QOJ.ac

QOJ

Límite de tiempo: 1.5 s Límite de memoria: 128 MB Puntuación total: 100

#11291. 沙拉吧

Estadísticas

Bytea 去了一家沙拉吧。柜台上摆放着 $n$ 个水果,它们一个接一个地排列。具体来说,这些水果是苹果和橙子。Bytea 可以选择水果队列中任意一段连续的部分来制作沙拉。

她所选的水果可以按从左到右或从右到左的顺序加入沙拉。由于 Bytea 非常喜欢橙子,她要求在制作沙拉的整个过程中,无论是以从左到右还是从右到左的顺序加入,沙拉中橙子的数量始终不能少于苹果的数量。请编写一个程序,帮助 Bytea 找出满足她要求的最长连续水果片段。

输入格式

输入的第一行包含一个整数 $n$ ($1 \le n \le 1\,000\,000$),表示水果的数量。第二行包含一个长度为 $n$ 的字符串 $a_{1}a_{2}…a_{n}$ ($a_{i} \in \{j, p\}$)。这些字符代表波兰语中苹果(jabłka)和橙子(pomarańcze)的首字母。因此,如果 $a_{i}=j$,则第 $i$ 个水果是苹果,否则是橙子。

输出格式

输出的第一行也是唯一一行应包含一个整数,等于满足 Bytea 要求的最长连续水果片段的长度。注意,结果也可能是 0。

样例

输入 1

6
jpjppj

输出 1

4

说明

一旦去掉了最左侧和最右侧的苹果,Bytea 就可以用剩余的所有水果制作沙拉。

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.