#P3015. Balanced Parentheses Score Computation
Balanced Parentheses Score Computation
Balanced Parentheses Score Computation
Given a balanced parentheses string, compute its score using the following rules:
- The string
()
has a score of 1. - If a string
A
has score \(s(A)\), then the string(A)
has score \(2\times s(A)\). - If strings
A
andB
have scores \(s(A)\) and \(s(B)\) respectively, then the concatenated stringAB
has score \(s(A)+s(B)\).
For example, the string (())()
is scored as follows:
\(s((())()) = s((())) + s(()) = 2\times1 + 1 = 3\).
inputFormat
The input consists of a single line containing a balanced parentheses string of length \(N\) where \(2 \le N \le 100000\).
outputFormat
Output a single integer representing the score of the given parentheses string.
sample
()
1
</p>