------
## 最终结论
```python
def score_of_parentheses(S: str) -> int:
    stack = []
    current_score = 0

    for char in S:
        if char == '(':
            stack.append(current_score)
            current_score = 0
        else:  # char == ')'
            current_score = stack.pop() + max(2 * current_score, 1)

    return current_score
```