No.3210 Fixed Sign Sequense
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もしくは右上の雲マークをクリックしてアカウントを作成してください。
Cafe1942