#abc240h. Ex - Sequence of Substrings
Ex - Sequence of Substrings
Score : points
问题描述
给定一个长度为 的字符串 ,其中包含 和 。
找出满足以下三个条件的最大整数 ,以及对应的序列 $\big((L_1, R_1), (L_2, R_2), \ldots, (L_K, R_K)\big)$。
- 对于每个 ,有 。
- 对于 ,满足 。
- 字符串 在字典序上严格小于字符串 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a string of length consisting of 's and 's.
Find the maximum integer such that there is a sequence of pairs of integers $\big((L_1, R_1), (L_2, R_2), \ldots, (L_K, R_K)\big)$ that satisfy all three conditions below.
- for each .
- for .
- The string is strictly lexicographically smaller than the string .
Constraints
- is an integer.
- is a string of length consisting of 's and 's.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
7
0101010
Sample Output 1
3
For , 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, is strictly lexicographically smaller than , and is strictly lexicographically smaller than .
For , 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
update @ 2024/3/10 10:22:36