#P15730. [JAG 2024 Summer Camp #2] Broken Parentheses
[JAG 2024 Summer Camp #2] Broken Parentheses
题目描述
Let us define a correct parenthesis sequence as a string that satisfies any of the following conditions:
- It is an empty string.
- It is formed by concatenating , , in this order where is a correct parenthesis sequence.
- It is formed by concatenating and in this order where and are non-empty correct parenthesis sequences.
Given a string of length consisting of the characters and .
For each where , define the string as the string obtained by concatenating the suffix of of length and the reversed string of the prefix of of length , in this order. That is, if we denote the -th character of as , the string is formed by arranging the characters $S_{i+1}, S_{i+2}, \ldots, S_N, S_i, \ldots, S_2, S_1$ in sequence.
For each where , solve the following problem:
- Consider an operation where you replace one character in with either or . Find the minimum number of such operations required to make a correct parenthesis sequence.
输入格式
The input is given in the following format:
- is even.
- is a string of length consisting only of and .
输出格式
Output lines. On the -th line, output the answer for .
4
()()
0
2
2
2
2
6
)))(((
4
2
2
0
0
0
0
8
)())())(
3
1
3
1
1
1
1
1
1