問題一覧 > 通常問題

No.3210 Fixed Sign Sequense

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 125
作問者 : 👑 loop0919 / テスター : yuusaan lif4635 Cafe1942
お気に入りにしたユーザー ProblemId : 12383 / 自分の提出
問題文最終更新日: 2025-07-25 21:11:48
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 475 (ゆるCafe) (順位表) の他の問題:

Problem Statement

You are given a positive integer $N$ and a string $S$ of length $N$ consisting of +, 0, and -.

An integer sequence $A$ of length $N$ is called a happy sequence if the following conditions are satisfied for every $i ~ (1 \leq i \leq N)$.

  • If the $i$-th character of $S$ is +, then $A_i > 0$.
  • If the $i$-th character of $S$ is 0, then $A_i = 0$.
  • If the $i$-th character of $S$ is -, then $A_i < 0$.

Find the maximum possible length of a longest increasing subsequence of a happy sequence of length $N$.

Here, a longest increasing subsequence of a sequence $X$ is a subsequence of $X$ (not necessarily contiguous) that is strictly increasing and has the maximum length among such subsequences.

Constraints

  • $1 \leq N \leq 3 \times 10^5$
  • $N$ is an integer.
  • $S$ is a string of length $N$ consisting of +, 0, and -.

Input

The input is given from Standard Input in the following format.

$N$
$S$

Output

Output the maximum possible length of a longest increasing subsequence of a happy sequence of length $N$.

Sample

Sample 1
Input
5
-+-+0
Output
3

If the happy sequence $A$ is $(-1, 1, -2, 2, 0)$, a longest increasing subsequence of $A$ is $(-1, 1, 2)$.

No happy sequence has a longest increasing subsequence of length $4$ or more, so the answer is $3$.

Sample 2
Input
3
+0-
Output
1

For any happy sequence, the length of a longest increasing subsequence cannot be $2$ or more.

Sample 3
Input
12
+-+-00+-+-00
Output
5

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。