#abc299c. C - Dango
C - Dango
Score : points
问题描述
对于一个正整数 ,级别为 的团子串是一个满足以下条件的字符串。
- 它是由
o
和-
组成的长度为 的字符串。 - 第一个字符和最后一个字符中恰好有一个是
-
,其余 个字符均为o
。
例如,ooo-
是一个级别为3的团子串,但 -ooo-
、oo
和 o-oo-
均不是团子串(更准确地说,它们都不是任何正整数 级别的团子串)。
给定一个由字符 o
和 -
组成的长度为 的字符串 。找出满足以下条件的最大正整数 。
- 字符串 中存在一个连续子串,它是级别为 的团子串。
如果没有这样的整数,请输出 -1
。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
For a positive integer , a level- dango string is a string that satisfies the following conditions.
- It is a string of length consisting of
o
and-
. - Exactly one of the first character and the last character is
-
, and the other characters areo
.
For instance, ooo-
is a level- dango string, but none of -ooo-
, oo
, and o-oo-
is a dango string (more precisely, none of them is a level- dango string for any positive integer ).
You are given a string of length consisting of the two characters o
and -
. Find the greatest positive integer that satisfies the following condition.
- There is a contiguous substring of that is a level- dango string.
If there is no such integer, print -1
.
Constraints
- is a string of length consisting of
o
and-
.
Input
The input is given from Standard Input in the following format:
Output
Print the greatest positive integer such that contains a level- dango string, or -1
if there is no such integer.
Sample Input 1
10
o-oooo---o
Sample Output 1
4
For instance, the substring oooo-
corresponding to the -rd through -th characters of is a level- dango string. No substring of is a level- dango string or above, so you should print .
Sample Input 2
1
-
Sample Output 2
-1
Only the empty string and -
are the substrings of . They are not dango strings, so you should print -1
.
Sample Input 3
30
-o-o-oooo-oo-o-ooooooo--oooo-o
Sample Output 3
7
update @ 2024/3/10 12:24:20