시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 1024 MB | 22 | 13 | 11 | 55.000% |
The number of parentheses and the level of nesting are usually a good indication of how complicated an expression is.
Given a string containing only “(”, “)” and blanks (spaces), compute its complexity. The complexity is defined as follows:
There is only one input line; it contains a valid expression. The expression (string) will be 2-60 characters, each character being either “(”, “)” or blank (space). Note that the blanks can be anywhere but the string will not exceed 60 characters (including the blanks). Assume that there will be at least one set of parentheses in the input, i.e., the input will not be all blanks.
Note that a valid expression satisfies the following:
Note again that the input is a valid expression, i.e., you do not need to check for errors.
Print the complexity of the expression.
()()()()()
5
( () ( ) () ( ) )
6
( (()) () (()) )
10
((())) () ( (()) () (()) )
17
(((((((((((((((((((())))))))))))))))))))
210
Note: The last Sample Input has parentheses nested 20 levels.