#P7248. [BalticOI 2012] 括号 (Day1)
[BalticOI 2012] 括号 (Day1)
Description
A valid bracket sequence is defined as follows:
()and[]are valid bracket sequences.- If is a valid bracket sequence, then and are also valid bracket sequences.
- If and are both valid bracket sequences, then is also a valid bracket sequence.
For a valid bracket sequence that contains at least one pair of square brackets, we can replace both [ and ] with (, and then we may obtain an invalid bracket sequence.
For example, (( and ((((())) are both invalid bracket sequences. The former can be transformed from the valid bracket sequence \[]. The latter can be transformed from the following four valid bracket sequences: \[]((())), (\[](())), ((\[]())), and (((\[]))).
Now you are given an invalid bracket sequence. Find how many valid bracket sequences can become the given sequence after replacing the square brackets in them with (.
Input Format
The first line contains a positive integer , which denotes the length of the given invalid bracket sequence.
The second line contains a string of length , representing the given sequence, which contains only ( and ).
Output Format
Output the number of valid bracket sequences that meet the requirement modulo .
4
((()
2
8
((((((((
14
Hint
Sample Explanation #1.
There are two valid bracket sequences that satisfy the condition: \[]() and ([]).
Constraints.
- For 20% of the testdata, .
- For 50% of the testdata, .
- For 100% of the testdata, .
Notes.
Translated from BalticOI 2012 Day1 T1. Brackets.
Translated by ChatGPT 5
京公网安备 11011102002149号