#abc283d. D - Scope
D - Scope
Score : points
问题描述
一个由小写英文字母、(
和 )
组成的字符串,如果可以通过以下过程变为一个空字符串,则称其为 好字符串:
- 首先,移除所有的小写英文字母。
- 然后,尽可能地重复移除连续的
()
。
例如,((a)ba)
是一个好字符串,因为移除所有小写英文字母后得到 (())
,从这个字符串中我们可以在第 个和第 个字符位置移除连续的 ()
得到 ()
,最终得到空字符串。
给定一个好字符串 。我们将 的第 个字符记为 。
对于每个小写英文字母 a
、b
、、z
,我们有一个上面写着该字母的球。另外,我们还有一个空盒子。
按照 的顺序,Takahashi 会依次执行以下操作,除非他晕倒。
- 如果 是一个小写英文字母,将写着该字母的球放入盒子中。如果该球已经存在于盒子里,那么他就会晕倒。
- 如果 是
(
,则不执行任何操作。 - 如果 是
)
,找到小于 的最大整数 ,使得 的第 个到第 个字符构成一个好字符串。(我们可以证明这样的整数 总是存在的。)取出他在第 次到第 次操作中放入盒子的所有球。
确定 Takahashi 是否能够在不晕倒的情况下完成这一系列操作。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
A string consisting of lowercase English letters, (
, and )
is said to be a good string if you can make it an empty string by the following procedure:
- First, remove all lowercase English letters.
- Then, repeatedly remove consecutive
()
while possible.
For example, ((a)ba)
is a good string, because removing all lowercase English letters yields (())
, from which we can remove consecutive ()
at the -nd and -rd characters to obtain ()
, which in turn ends up in an empty string.
You are given a good string . We denote by the -th character of .
For each lowercase English letter a
, b
, , and z
, we have a ball with the letter written on it. Additionally, we have an empty box.
For each in this order, Takahashi performs the following operation unless he faints.
- If is a lowercase English letter, put the ball with the letter written on it into the box. If the ball is already in the box, he faints.
- If is
(
, do nothing. - If is
)
, take the maximum integer less than such that the -th through -th characters of form a good string. (We can prove that such an integer always exists.) Take out from the box all the balls that he has put in the -th through -th operations.
Determine if Takahashi can complete the sequence of operations without fainting.
Constraints
- is a good string.
Input
The input is given from Standard Input in the following format:
Output
Print Yes
if he can complete the sequence of operations without fainting; print No
otherwise.
Sample Input 1
((a)ba)
Sample Output 1
Yes
For , he does nothing.
For , he does nothing.
For , he puts the ball with a
written on it into the box.
For , is the maximum integer less than such that the -th through -th characters of form a good string, so he takes out the ball with a
written on it from the box.
For , he puts the ball with b
written on it into the box.
For , he puts the ball with a
written on it into the box.
For , is the maximum integer less than such that the -th through -th characters of form a good string, so he takes out the ball with a
written on it, and another with b
, from the box.
Therefore, the answer to this case is Yes
.
Sample Input 2
(a(ba))
Sample Output 2
No
For , he does nothing.
For , he puts the ball with a
written on it into the box.
For , he does nothing.
For , he puts the ball with b
written on it into the box.
For , the ball with a
written on it is already in the box, so he faints, aborting the sequence of operations.
Therefore, the answer to this case is No
.
Sample Input 3
(((())))
Sample Output 3
Yes
Sample Input 4
abca
Sample Output 4
No
update @ 2024/3/10 11:52:12