-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathBRCKTS2.cpp
More file actions
53 lines (47 loc) · 730 Bytes
/
BRCKTS2.cpp
File metadata and controls
53 lines (47 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
USER: zobayer
TASK: BRCKTS2
ALGO: recursion
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define i64 long long
#define MAX 350000
char str[MAX+1];
void recur(i64 &h, i64 &w, int d, int &pos, i64 &area)
{
i64 maxH = 0, newW, newH;
pos++;
while(str[pos]=='(')
{
newH = newW = 1;
recur(newH, newW, d+1, pos, area);
w += newW + 1;
maxH = max(newH, maxH);
pos++;
}
h = maxH + 1;
if(d & 1) area += w * h;
else area -= w*h;
}
int main()
{
int t, len, i;
i64 w, h, area;
scanf("%d", &t);
while(t--)
{
scanf("%s", str);
len = strlen(str);
area = 0;
for(i=0; i<len; i++)
{
h = w = 1;
recur(h, w, 1, i, area);
}
printf("%lld\n", area);
}
return 0;
}