102407: [AtCoder]ABC240 Ex - Sequence of Substrings

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

You are given a string $S = s_1 s_2 \ldots s_N$ of length $N$ consisting of $0$'s and $1$'s.

Find the maximum integer $K$ such that there is a sequence of $K$ pairs of integers $\big((L_1, R_1), (L_2, R_2), \ldots, (L_K, R_K)\big)$ that satisfy all three conditions below.

  • $1 \leq L_i \leq R_i \leq N$ for each $i = 1, 2, \ldots, K$.
  • $R_i \lt L_{i+1}$ for $i = 1, 2, \ldots, K-1$.
  • The string $s_{L_i}s_{L_i+1} \ldots s_{R_i}$ is strictly lexicographically smaller than the string $s_{L_{i+1}}s_{L_{i+1}+1}\ldots s_{R_{i+1}}$.

Constraints

  • $1 \leq N \leq 2.5 \times 10^4$
  • $N$ is an integer.
  • $S$ is a string of length $N$ consisting of $0$'s and $1$'s.

Input

Input is given from Standard Input in the following format:

$N$
$S$

Output

Print the answer.


Sample Input 1

7
0101010

Sample Output 1

3

For $K = 3$, one sequence satisfying the conditition is $(L_1, R_1) = (1, 1), (L_2, R_2) = (3, 5), (L_3, R_3) = (6, 7)$. Indeed, $s_1 = 0$ is strictly lexicographically smaller than $s_3s_4s_5 = 010$, and $s_3s_4s_5 = 010$ is strictly lexicographically smaller than $s_6s_7 = 10$.
For $K \geq 4$, there is no sequence $\big((L_1, R_1), (L_2, R_2), \ldots, (L_K, R_K)\big)$ satisfying the condition.


Sample Input 2

30
000011001110101001011110001001

Sample Output 2

9

Input

题意翻译

给定一个长度为 $n$ 的 $01$ 串,求最多可以选出多少互不相交的子串,满足这些子串按照原串中的顺序,字典序严格升序。

Output

分数:600分

问题描述

给你一个长度为 N 的字符串 $S = s_1 s_2 \ldots s_N$,由 0 和 1 组成。

找到最大的整数 $K$,使得存在一个整数对序列 $\big((L_1, R_1), (L_2, R_2), \ldots, (L_K, R_K)\big)$ 满足以下三个条件。

  • 对于每个 $i = 1, 2, \ldots, K$,都有 $1 \leq L_i \leq R_i \leq N$。
  • 对于 $i = 1, 2, \ldots, K-1$,都有 $R_i \lt L_{i+1}$。
  • 字符串 $s_{L_i}s_{L_i+1} \ldots s_{R_i}$ 严格字典序小于 字符串 $s_{L_{i+1}}s_{L_{i+1}+1}\ldots s_{R_{i+1}}$。

限制条件

  • $1 \leq N \leq 2.5 \times 10^4$
  • $N$ 是一个整数。
  • $S$ 是一个长度为 $N$ 的字符串,由 0 和 1 组成。

输入

输入从标准输入中给出,格式如下:

$N$
$S$

输出

打印答案。


样例输入 1

7
0101010

样例输出 1

3

对于 $K = 3$,一个满足条件的序列是 $(L_1, R_1) = (1, 1), (L_2, R_2) = (3, 5), (L_3, R_3) = (6, 7)$。 确实,$s_1 = 0$ 严格字典序小于 $s_3s_4s_5 = 010$,且 $s_3s_4s_5 = 010$ 严格字典序小于 $s_6s_7 = 10$。

对于 $K \geq 4$,不存在满足条件的序列 $\big((L_1, R_1), (L_2, R_2), \ldots, (L_K, R_K)\big)$。


样例输入 2

30
000011001110101001011110001001

样例输出 2

9

加入题单

算法标签: