#P7044. 「MCOI-03」括号
「MCOI-03」括号
Description
Define the level deviation value of a bracket string as the minimum number of operations needed to modify this bracket string into a valid bracket sequence. In one operation, you can insert a bracket at some position or delete a bracket at some position.
For , define the level deviation value of the string as the sum of the level deviation values over all substrings of this string.
Now you need to compute the level deviation value of a bracket string of length . The answer may be very large; output the result modulo .
Input Format
The first line contains two integers .
The second line contains a string representing the bracket sequence .
Output Format
Output one integer, the answer modulo .
3 1
(()
6
3 2
(()
15
Hint
Sample Explanation
For sample , the level costs of all substrings of are:
- , cost is .
- , cost is .
- , cost is .
- , cost is .
- , cost is .
- , cost is .
The total is .
Constraints
This problem uses bundled testdata.
| Subtask ID | Score | ||
|---|---|---|---|
For of the testdata, .
Original idea: WAPER420
Translated by ChatGPT 5
京公网安备 11011102002149号