Good Bye 2022: 2023 is NEAR
G
Koxia and Bracket
Codeforces
3400
原题
← FH →
翻译中…

Chiyuu has a bracket sequence$^\dagger$ $s$ of length $n$. Let $k$ be the minimum number of characters that Chiyuu has to remove from $s$ to make $s$ balanced$^\ddagger$.

翻译中…

Now, Koxia wants you to count the number of ways to remove $k$ characters from $s$ so that $s$ becomes balanced, modulo $998\,244\,353$.

翻译中…

Note that two ways of removing characters are considered distinct if and only if the set of indices removed is different.

翻译中…

$^\dagger$ A bracket sequence is a string containing only the characters "(" and ")".

翻译中…

$^\ddagger$ 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.

翻译中…

Input

翻译中…

The first line of input contains a string $s$ ($1 \leq |s| \leq 5 \cdot {10}^5$) — the bracket sequence.

翻译中…

It is guaranteed that $s$ only contains the characters "(" and ")".

翻译中…

Output

翻译中…

Output a single integer — the number of ways to remove $k$ characters from $s$ so that $s$ becomes balanced, modulo $998\,244\,353$.

翻译中…

Note

翻译中…

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.

翻译中…
  • $\texttt{(} \color{Red}{\texttt{)}} \texttt{)} \color{Red}{\texttt{(}} \texttt{(} \texttt{)}$,
  • $\texttt{(} \texttt{)} \color{Red}{\texttt{)}} \color{Red}{\texttt{(}} \texttt{(} \texttt{)}$,
  • $\texttt{(} \color{Red}{\texttt{)}} \texttt{)} \texttt{(} \color{Red}{\texttt{(}} \texttt{)}$,
  • $\texttt{(} \texttt{)} \color{Red}{\texttt{)}} \texttt{(} \color{Red}{\texttt{(}} \texttt{)}$.
翻译中…

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.

翻译中…

样例

Input #1
())(()
Output #1
4
InputCopy OutputCopy
Input #2
(
Output #2
1
InputCopy OutputCopy
题目信息
题号
1770G
时间限制
5 s
内存限制
256 MB
标签
分治
FFT
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。