아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Easy representation

시간 제한1초메모리 제한1024 MB

요약
올바른 괄호열이 주어질 때, 기하학적 표현에서 가장 바깥 영역부터 번갈아 칠한 검정 영역의 넓이를 구한다.
난이도

보통10점 중 6점

유형
스택, 구현, 수학, 조합론
정답자
아직 제출이 없습니다

문제

Peter is preparing slides for his lecture on parsing arithmetic expressions. In the first part of the lecture he wants to focus just on parsing brackets. He invented an interesting geometric representation of a correct bracket sequence for his students, because one image is better than a thousand words:

(())(()(())) =

Formally, the definition of the geometric representation looks as follows. The simplest correct bracket sequence () is represented by a 1 × 1 square. If A is a correct bracket sequence and g(A) its represenation, then the representation for (A) is g(A) surrounded by a rectangle two units wider than g(A) and one unit taller than the highest point of g(A). If A and B are two correct bracket sequences and g(A) and g(B) are their representations, then we get g(AB) by placing g(B) one unit to the right of g(A).

After he finished his slides, Peter started to play with the images he prepared. He painted the bounded areas of the images alternately black and white, in such a way that the outer-most areas are all painted black. For the example above this coloring looks as follows:

You are given a correct bracket sequence. Calculate the area that is colored black.

입력

The first line of the input file contains an integer T specifying the number of test cases. Each test case is preceded by a blank line. Each test case consists of one line with a correct bracket sequence. Every line will only contain characters ‘(’ and ‘)’.

출력

For each test case output one line with one integer – the area of the black part of the corresponding geometric representation.

힌트

The second test case is the one shown in the pictures above.

예제1

  1. 예제 1

    입력
    2
    
    ((()))
    
    (())(()(()))
    
    예상 출력
    10 
    20