#abc312d. D - Count Bracket Sequences
D - Count Bracket Sequences
Score : points
问题描述
给定一个非空字符串 ,其中包含字符 (
、)
和 ?
。
对于 中出现的每个 ?
,有 种方式通过用 (
和 )
替换它来得到一个新的字符串,其中 是 中 ?
出现的次数。在这些方式中,找出满足括号字符串条件的方案数,结果对 取模。
若字符串满足以下任一条件,则称其为括号字符串:
- 它是一个空字符串。
- 它是形如
(
、 和)
的串联形式,其中 是某个括号字符串。 - 它是形如 和 的串联形式,其中 和 是两个非空的括号字符串。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a non-empty string consisting of (
, )
, and ?
.
There are ways to obtain a new string by replacing each ?
in with (
and )
, where is the number of occurrences of ?
in . Among them, find the number, modulo , of ways that yield a parenthesis string.
A string is said to be a parenthesis string if one of the following conditions is satisfied.
- It is an empty string.
- It is a concatenation of
(
, , and)
, for some parenthesis string . - It is a concatenation of and , for some non-empty parenthesis strings and .
Constraints
- is a non-empty string of length at most consisting of
(
,)
, and?
.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
(???(?
Sample Output 1
2
Replacing with ()()()
or (())()
yields a parenthesis string.
The other replacements do not yield a parenthesis string, so should be printed.
Sample Input 2
)))))
Sample Output 2
0
Sample Input 3
??????????????(????????(??????)?????????(?(??)
Sample Output 3
603032273
Print the count modulo .
update @ 2024/3/10 08:53:33
相关
在以下作业中: