A15631 | Koxia and Bracket
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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 ")".
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 $998\,244\,353$ .
输入输出样例
输入 #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.
- $\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.
- $\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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted