CF1374C.Move Brackets
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a bracket sequence s of length n , where n is even (divisible by two). The string s consists of 2n opening brackets '(' and 2n closing brackets ')'.
In one move, you can choose exactly one bracket and move it to the beginning of the string or to the end of the string (i.e. you choose some index i , remove the i -th character of s and insert it before or after all remaining characters of s ).
Your task is to find the minimum number of moves required to obtain regular bracket sequence from s . It can be proved that the answer always exists under the given constraints.
Recall what the regular bracket sequence is:
- "()" is regular bracket sequence;
- if s is regular bracket sequence then "(" + s + ")" is regular bracket sequence;
- if s and t are regular bracket sequences then s + t is regular bracket sequence.
For example, "()()", "(())()", "(())" and "()" are regular bracket sequences, but ")(", "()(" and ")))" are not.
You have to answer t independent test cases.
输入格式
The first line of the input contains one integer t ( 1≤t≤2000 ) — the number of test cases. Then t test cases follow.
The first line of the test case contains one integer n ( 2≤n≤50 ) — the length of s . It is guaranteed that n is even. The second line of the test case containg the string s consisting of 2n opening and 2n closing brackets.
输出格式
For each test case, print the answer — the minimum number of moves required to obtain regular bracket sequence from s . It can be proved that the answer always exists under the given constraints.
输入输出样例
输入#1
4 2 )( 4 ()() 8 ())()()( 10 )))((((())
输出#1
1 0 1 3
说明/提示
In the first test case of the example, it is sufficient to move the first bracket to the end of the string.
In the third test case of the example, it is sufficient to move the last bracket to the beginning of the string.
In the fourth test case of the example, we can choose last three openning brackets, move them to the beginning of the string and obtain "((()))(())".