CF1770G.Koxia and Bracket
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Chiyuu has a bracket sequence † s of length n . Let k be the minimum number of characters that Chiyuu has to remove from s to make s balanced ‡ .
Now, Koxia wants you to count the number of ways to remove k characters from s so that s becomes balanced, modulo 998244353 .
Note that two ways of removing characters are considered distinct if and only if the set of indices removed is different.
† A bracket sequence is a string containing only the characters "(" and ")".
‡ A bracket sequence is called balanced if one can turn it into a valid math expression by adding characters + and 1. For example, sequences (())(), (), (()(())) and the empty string are balanced, while )(, ((), and (()))( are not.
输入格式
The first line of input contains a string s ( 1≤∣s∣≤5⋅105 ) — the bracket sequence.
It is guaranteed that s only contains the characters "(" and ")".
输出格式
Output a single integer — the number of ways to remove k characters from s so that s becomes balanced, modulo 998244353 .
输入输出样例
输入#1
())(()
输出#1
4
输入#2
(
输出#2
1
说明/提示
In the first test case, it can be proved that the minimum number of characters that Chiyuu has to remove is 2 . There are 4 ways to remove 2 characters to make s balanced as follows. Deleted characters are noted as red.
- ())(() ,
- ())(() ,
- ())(() ,
- ())(() .
In the second test case, the only way to make s balanced is by deleting the only character to get an empty bracket sequence, which is considered balanced.