#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,l,r) for(int i=l; i<r; i++)
#define all(x) x.begin(),x.end()
#define len(x) (int)x.size();
#define fi first
#define se second
#define elif else if
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
constexpr ll LINF=1001001001001001001LL;
constexpr ll MINF=1001001001001LL;
constexpr int INF=1001001001;
constexpr int MAX_N=1001001;
string S;
int sz;
vector<vector<int>> comma(MAX_N);
array<int,3> calc(int lf,int ri,int lv){
if(ri-lf==1)return {0,1,1};
int cp=*lower_bound(all(comma[lv]),lf);
array<int,3> left=calc(lf+4,cp,lv+1);
array<int,3> right=calc(cp+1,ri-1,lv+1);
array<int,3> ret={0,0,left[2]+right[2]};
if(S[lf+1]=='i'){
tie(left[0],left[1])=pii{left[2]-left[1],left[2]-left[0]};
tie(right[0],right[1])=pii{right[2]-right[1],right[2]-right[0]};
}
//TODO:make_max
ret[0]=left[0]+right[0]+1;
ret[1]=max(left[2]+right[1],right[2]+left[1]);
if(S[lf+1]=='i'){
tie(ret[0],ret[1])=pii{ret[2]-ret[1],ret[2]-ret[0]};
}
return ret;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>S;
sz=len(S);
int level=0;
rep(i,sz){
if(S[i]=='(')level++;
elif(S[i]==')')level--;
elif(S[i]==',')comma[level-1].emplace_back(i);
}
array<int,3> ans=calc(0,sz,0);
cout<<ans[1]-ans[0]<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
Output is correct |
2 |
Correct |
11 ms |
23952 KB |
Output is correct |
3 |
Correct |
10 ms |
23880 KB |
Output is correct |
4 |
Correct |
11 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
23716 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23824 KB |
Output is correct |
8 |
Correct |
10 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23960 KB |
Output is correct |
10 |
Correct |
12 ms |
23896 KB |
Output is correct |
11 |
Correct |
10 ms |
23944 KB |
Output is correct |
12 |
Correct |
11 ms |
23896 KB |
Output is correct |
13 |
Correct |
10 ms |
23900 KB |
Output is correct |
14 |
Correct |
10 ms |
23960 KB |
Output is correct |
15 |
Correct |
14 ms |
23900 KB |
Output is correct |
16 |
Correct |
10 ms |
23900 KB |
Output is correct |
17 |
Correct |
10 ms |
23900 KB |
Output is correct |
18 |
Correct |
9 ms |
23900 KB |
Output is correct |
19 |
Correct |
10 ms |
23900 KB |
Output is correct |
20 |
Correct |
9 ms |
23748 KB |
Output is correct |
21 |
Correct |
10 ms |
23900 KB |
Output is correct |
22 |
Correct |
9 ms |
23772 KB |
Output is correct |
23 |
Correct |
10 ms |
24148 KB |
Output is correct |
24 |
Correct |
10 ms |
23900 KB |
Output is correct |
25 |
Correct |
11 ms |
23720 KB |
Output is correct |
26 |
Correct |
10 ms |
23900 KB |
Output is correct |
27 |
Correct |
10 ms |
23900 KB |
Output is correct |
28 |
Correct |
10 ms |
23900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
Output is correct |
2 |
Correct |
11 ms |
23952 KB |
Output is correct |
3 |
Correct |
10 ms |
23880 KB |
Output is correct |
4 |
Correct |
11 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
23716 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23824 KB |
Output is correct |
8 |
Correct |
10 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23960 KB |
Output is correct |
10 |
Correct |
12 ms |
23896 KB |
Output is correct |
11 |
Correct |
10 ms |
23944 KB |
Output is correct |
12 |
Correct |
11 ms |
23896 KB |
Output is correct |
13 |
Correct |
10 ms |
23900 KB |
Output is correct |
14 |
Correct |
10 ms |
23960 KB |
Output is correct |
15 |
Correct |
14 ms |
23900 KB |
Output is correct |
16 |
Correct |
10 ms |
23900 KB |
Output is correct |
17 |
Correct |
10 ms |
23900 KB |
Output is correct |
18 |
Correct |
9 ms |
23900 KB |
Output is correct |
19 |
Correct |
10 ms |
23900 KB |
Output is correct |
20 |
Correct |
9 ms |
23748 KB |
Output is correct |
21 |
Correct |
10 ms |
23900 KB |
Output is correct |
22 |
Correct |
9 ms |
23772 KB |
Output is correct |
23 |
Correct |
10 ms |
24148 KB |
Output is correct |
24 |
Correct |
10 ms |
23900 KB |
Output is correct |
25 |
Correct |
11 ms |
23720 KB |
Output is correct |
26 |
Correct |
10 ms |
23900 KB |
Output is correct |
27 |
Correct |
10 ms |
23900 KB |
Output is correct |
28 |
Correct |
10 ms |
23900 KB |
Output is correct |
29 |
Correct |
10 ms |
23900 KB |
Output is correct |
30 |
Correct |
12 ms |
23900 KB |
Output is correct |
31 |
Correct |
10 ms |
23944 KB |
Output is correct |
32 |
Correct |
10 ms |
23768 KB |
Output is correct |
33 |
Correct |
10 ms |
23828 KB |
Output is correct |
34 |
Correct |
11 ms |
23900 KB |
Output is correct |
35 |
Correct |
10 ms |
23900 KB |
Output is correct |
36 |
Correct |
10 ms |
23892 KB |
Output is correct |
37 |
Correct |
10 ms |
23756 KB |
Output is correct |
38 |
Correct |
12 ms |
23900 KB |
Output is correct |
39 |
Correct |
10 ms |
23964 KB |
Output is correct |
40 |
Correct |
10 ms |
23900 KB |
Output is correct |
41 |
Correct |
11 ms |
23900 KB |
Output is correct |
42 |
Correct |
9 ms |
23900 KB |
Output is correct |
43 |
Correct |
9 ms |
23900 KB |
Output is correct |
44 |
Correct |
9 ms |
23900 KB |
Output is correct |
45 |
Correct |
10 ms |
23900 KB |
Output is correct |
46 |
Correct |
15 ms |
23900 KB |
Output is correct |
47 |
Correct |
14 ms |
23896 KB |
Output is correct |
48 |
Correct |
11 ms |
23896 KB |
Output is correct |
49 |
Correct |
10 ms |
23900 KB |
Output is correct |
50 |
Correct |
9 ms |
23896 KB |
Output is correct |
51 |
Correct |
10 ms |
23900 KB |
Output is correct |
52 |
Correct |
14 ms |
23872 KB |
Output is correct |
53 |
Correct |
9 ms |
23900 KB |
Output is correct |
54 |
Correct |
9 ms |
23900 KB |
Output is correct |
55 |
Correct |
14 ms |
24056 KB |
Output is correct |
56 |
Correct |
11 ms |
23900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
187340 KB |
Output is correct |
2 |
Correct |
180 ms |
187340 KB |
Output is correct |
3 |
Correct |
182 ms |
187340 KB |
Output is correct |
4 |
Correct |
191 ms |
187344 KB |
Output is correct |
5 |
Correct |
166 ms |
187344 KB |
Output is correct |
6 |
Correct |
165 ms |
187248 KB |
Output is correct |
7 |
Correct |
161 ms |
187340 KB |
Output is correct |
8 |
Correct |
161 ms |
187340 KB |
Output is correct |
9 |
Correct |
177 ms |
187172 KB |
Output is correct |
10 |
Correct |
216 ms |
187124 KB |
Output is correct |
11 |
Correct |
166 ms |
187344 KB |
Output is correct |
12 |
Correct |
160 ms |
187340 KB |
Output is correct |
13 |
Correct |
10 ms |
23896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
Output is correct |
2 |
Correct |
11 ms |
23952 KB |
Output is correct |
3 |
Correct |
10 ms |
23880 KB |
Output is correct |
4 |
Correct |
11 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
23716 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23824 KB |
Output is correct |
8 |
Correct |
10 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23960 KB |
Output is correct |
10 |
Correct |
12 ms |
23896 KB |
Output is correct |
11 |
Correct |
10 ms |
23944 KB |
Output is correct |
12 |
Correct |
11 ms |
23896 KB |
Output is correct |
13 |
Correct |
10 ms |
23900 KB |
Output is correct |
14 |
Correct |
10 ms |
23960 KB |
Output is correct |
15 |
Correct |
14 ms |
23900 KB |
Output is correct |
16 |
Correct |
10 ms |
23900 KB |
Output is correct |
17 |
Correct |
10 ms |
23900 KB |
Output is correct |
18 |
Correct |
9 ms |
23900 KB |
Output is correct |
19 |
Correct |
10 ms |
23900 KB |
Output is correct |
20 |
Correct |
9 ms |
23748 KB |
Output is correct |
21 |
Correct |
10 ms |
23900 KB |
Output is correct |
22 |
Correct |
9 ms |
23772 KB |
Output is correct |
23 |
Correct |
10 ms |
24148 KB |
Output is correct |
24 |
Correct |
10 ms |
23900 KB |
Output is correct |
25 |
Correct |
11 ms |
23720 KB |
Output is correct |
26 |
Correct |
10 ms |
23900 KB |
Output is correct |
27 |
Correct |
10 ms |
23900 KB |
Output is correct |
28 |
Correct |
10 ms |
23900 KB |
Output is correct |
29 |
Correct |
10 ms |
23900 KB |
Output is correct |
30 |
Correct |
12 ms |
23900 KB |
Output is correct |
31 |
Correct |
10 ms |
23944 KB |
Output is correct |
32 |
Correct |
10 ms |
23768 KB |
Output is correct |
33 |
Correct |
10 ms |
23828 KB |
Output is correct |
34 |
Correct |
11 ms |
23900 KB |
Output is correct |
35 |
Correct |
10 ms |
23900 KB |
Output is correct |
36 |
Correct |
10 ms |
23892 KB |
Output is correct |
37 |
Correct |
10 ms |
23756 KB |
Output is correct |
38 |
Correct |
12 ms |
23900 KB |
Output is correct |
39 |
Correct |
10 ms |
23964 KB |
Output is correct |
40 |
Correct |
10 ms |
23900 KB |
Output is correct |
41 |
Correct |
11 ms |
23900 KB |
Output is correct |
42 |
Correct |
9 ms |
23900 KB |
Output is correct |
43 |
Correct |
9 ms |
23900 KB |
Output is correct |
44 |
Correct |
9 ms |
23900 KB |
Output is correct |
45 |
Correct |
10 ms |
23900 KB |
Output is correct |
46 |
Correct |
15 ms |
23900 KB |
Output is correct |
47 |
Correct |
14 ms |
23896 KB |
Output is correct |
48 |
Correct |
11 ms |
23896 KB |
Output is correct |
49 |
Correct |
10 ms |
23900 KB |
Output is correct |
50 |
Correct |
9 ms |
23896 KB |
Output is correct |
51 |
Correct |
10 ms |
23900 KB |
Output is correct |
52 |
Correct |
14 ms |
23872 KB |
Output is correct |
53 |
Correct |
9 ms |
23900 KB |
Output is correct |
54 |
Correct |
9 ms |
23900 KB |
Output is correct |
55 |
Correct |
14 ms |
24056 KB |
Output is correct |
56 |
Correct |
11 ms |
23900 KB |
Output is correct |
57 |
Correct |
10 ms |
23900 KB |
Output is correct |
58 |
Correct |
10 ms |
23896 KB |
Output is correct |
59 |
Correct |
11 ms |
23900 KB |
Output is correct |
60 |
Correct |
10 ms |
23900 KB |
Output is correct |
61 |
Correct |
16 ms |
23896 KB |
Output is correct |
62 |
Correct |
11 ms |
23900 KB |
Output is correct |
63 |
Correct |
11 ms |
23900 KB |
Output is correct |
64 |
Correct |
10 ms |
23832 KB |
Output is correct |
65 |
Correct |
10 ms |
23900 KB |
Output is correct |
66 |
Correct |
10 ms |
23896 KB |
Output is correct |
67 |
Correct |
10 ms |
23900 KB |
Output is correct |
68 |
Correct |
15 ms |
23900 KB |
Output is correct |
69 |
Correct |
10 ms |
23900 KB |
Output is correct |
70 |
Correct |
9 ms |
23900 KB |
Output is correct |
71 |
Correct |
9 ms |
23900 KB |
Output is correct |
72 |
Correct |
9 ms |
24044 KB |
Output is correct |
73 |
Correct |
11 ms |
23900 KB |
Output is correct |
74 |
Correct |
11 ms |
23900 KB |
Output is correct |
75 |
Correct |
11 ms |
23900 KB |
Output is correct |
76 |
Correct |
10 ms |
23900 KB |
Output is correct |
77 |
Correct |
9 ms |
23900 KB |
Output is correct |
78 |
Correct |
8 ms |
23900 KB |
Output is correct |
79 |
Correct |
8 ms |
23900 KB |
Output is correct |
80 |
Correct |
11 ms |
23820 KB |
Output is correct |
81 |
Correct |
11 ms |
23900 KB |
Output is correct |
82 |
Correct |
11 ms |
24044 KB |
Output is correct |
83 |
Correct |
10 ms |
23788 KB |
Output is correct |
84 |
Correct |
10 ms |
23900 KB |
Output is correct |
85 |
Correct |
10 ms |
23900 KB |
Output is correct |
86 |
Correct |
11 ms |
23900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23896 KB |
Output is correct |
2 |
Correct |
11 ms |
23952 KB |
Output is correct |
3 |
Correct |
10 ms |
23880 KB |
Output is correct |
4 |
Correct |
11 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
23716 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23824 KB |
Output is correct |
8 |
Correct |
10 ms |
23900 KB |
Output is correct |
9 |
Correct |
10 ms |
23960 KB |
Output is correct |
10 |
Correct |
12 ms |
23896 KB |
Output is correct |
11 |
Correct |
10 ms |
23944 KB |
Output is correct |
12 |
Correct |
11 ms |
23896 KB |
Output is correct |
13 |
Correct |
10 ms |
23900 KB |
Output is correct |
14 |
Correct |
10 ms |
23960 KB |
Output is correct |
15 |
Correct |
14 ms |
23900 KB |
Output is correct |
16 |
Correct |
10 ms |
23900 KB |
Output is correct |
17 |
Correct |
10 ms |
23900 KB |
Output is correct |
18 |
Correct |
9 ms |
23900 KB |
Output is correct |
19 |
Correct |
10 ms |
23900 KB |
Output is correct |
20 |
Correct |
9 ms |
23748 KB |
Output is correct |
21 |
Correct |
10 ms |
23900 KB |
Output is correct |
22 |
Correct |
9 ms |
23772 KB |
Output is correct |
23 |
Correct |
10 ms |
24148 KB |
Output is correct |
24 |
Correct |
10 ms |
23900 KB |
Output is correct |
25 |
Correct |
11 ms |
23720 KB |
Output is correct |
26 |
Correct |
10 ms |
23900 KB |
Output is correct |
27 |
Correct |
10 ms |
23900 KB |
Output is correct |
28 |
Correct |
10 ms |
23900 KB |
Output is correct |
29 |
Correct |
10 ms |
23900 KB |
Output is correct |
30 |
Correct |
12 ms |
23900 KB |
Output is correct |
31 |
Correct |
10 ms |
23944 KB |
Output is correct |
32 |
Correct |
10 ms |
23768 KB |
Output is correct |
33 |
Correct |
10 ms |
23828 KB |
Output is correct |
34 |
Correct |
11 ms |
23900 KB |
Output is correct |
35 |
Correct |
10 ms |
23900 KB |
Output is correct |
36 |
Correct |
10 ms |
23892 KB |
Output is correct |
37 |
Correct |
10 ms |
23756 KB |
Output is correct |
38 |
Correct |
12 ms |
23900 KB |
Output is correct |
39 |
Correct |
10 ms |
23964 KB |
Output is correct |
40 |
Correct |
10 ms |
23900 KB |
Output is correct |
41 |
Correct |
11 ms |
23900 KB |
Output is correct |
42 |
Correct |
9 ms |
23900 KB |
Output is correct |
43 |
Correct |
9 ms |
23900 KB |
Output is correct |
44 |
Correct |
9 ms |
23900 KB |
Output is correct |
45 |
Correct |
10 ms |
23900 KB |
Output is correct |
46 |
Correct |
15 ms |
23900 KB |
Output is correct |
47 |
Correct |
14 ms |
23896 KB |
Output is correct |
48 |
Correct |
11 ms |
23896 KB |
Output is correct |
49 |
Correct |
10 ms |
23900 KB |
Output is correct |
50 |
Correct |
9 ms |
23896 KB |
Output is correct |
51 |
Correct |
10 ms |
23900 KB |
Output is correct |
52 |
Correct |
14 ms |
23872 KB |
Output is correct |
53 |
Correct |
9 ms |
23900 KB |
Output is correct |
54 |
Correct |
9 ms |
23900 KB |
Output is correct |
55 |
Correct |
14 ms |
24056 KB |
Output is correct |
56 |
Correct |
11 ms |
23900 KB |
Output is correct |
57 |
Correct |
194 ms |
187340 KB |
Output is correct |
58 |
Correct |
180 ms |
187340 KB |
Output is correct |
59 |
Correct |
182 ms |
187340 KB |
Output is correct |
60 |
Correct |
191 ms |
187344 KB |
Output is correct |
61 |
Correct |
166 ms |
187344 KB |
Output is correct |
62 |
Correct |
165 ms |
187248 KB |
Output is correct |
63 |
Correct |
161 ms |
187340 KB |
Output is correct |
64 |
Correct |
161 ms |
187340 KB |
Output is correct |
65 |
Correct |
177 ms |
187172 KB |
Output is correct |
66 |
Correct |
216 ms |
187124 KB |
Output is correct |
67 |
Correct |
166 ms |
187344 KB |
Output is correct |
68 |
Correct |
160 ms |
187340 KB |
Output is correct |
69 |
Correct |
10 ms |
23896 KB |
Output is correct |
70 |
Correct |
10 ms |
23900 KB |
Output is correct |
71 |
Correct |
10 ms |
23896 KB |
Output is correct |
72 |
Correct |
11 ms |
23900 KB |
Output is correct |
73 |
Correct |
10 ms |
23900 KB |
Output is correct |
74 |
Correct |
16 ms |
23896 KB |
Output is correct |
75 |
Correct |
11 ms |
23900 KB |
Output is correct |
76 |
Correct |
11 ms |
23900 KB |
Output is correct |
77 |
Correct |
10 ms |
23832 KB |
Output is correct |
78 |
Correct |
10 ms |
23900 KB |
Output is correct |
79 |
Correct |
10 ms |
23896 KB |
Output is correct |
80 |
Correct |
10 ms |
23900 KB |
Output is correct |
81 |
Correct |
15 ms |
23900 KB |
Output is correct |
82 |
Correct |
10 ms |
23900 KB |
Output is correct |
83 |
Correct |
9 ms |
23900 KB |
Output is correct |
84 |
Correct |
9 ms |
23900 KB |
Output is correct |
85 |
Correct |
9 ms |
24044 KB |
Output is correct |
86 |
Correct |
11 ms |
23900 KB |
Output is correct |
87 |
Correct |
11 ms |
23900 KB |
Output is correct |
88 |
Correct |
11 ms |
23900 KB |
Output is correct |
89 |
Correct |
10 ms |
23900 KB |
Output is correct |
90 |
Correct |
9 ms |
23900 KB |
Output is correct |
91 |
Correct |
8 ms |
23900 KB |
Output is correct |
92 |
Correct |
8 ms |
23900 KB |
Output is correct |
93 |
Correct |
11 ms |
23820 KB |
Output is correct |
94 |
Correct |
11 ms |
23900 KB |
Output is correct |
95 |
Correct |
11 ms |
24044 KB |
Output is correct |
96 |
Correct |
10 ms |
23788 KB |
Output is correct |
97 |
Correct |
10 ms |
23900 KB |
Output is correct |
98 |
Correct |
10 ms |
23900 KB |
Output is correct |
99 |
Correct |
11 ms |
23900 KB |
Output is correct |
100 |
Correct |
90 ms |
36824 KB |
Output is correct |
101 |
Correct |
94 ms |
36568 KB |
Output is correct |
102 |
Correct |
89 ms |
36668 KB |
Output is correct |
103 |
Correct |
91 ms |
36580 KB |
Output is correct |
104 |
Correct |
86 ms |
36568 KB |
Output is correct |
105 |
Correct |
97 ms |
83156 KB |
Output is correct |
106 |
Correct |
100 ms |
83404 KB |
Output is correct |
107 |
Correct |
102 ms |
83152 KB |
Output is correct |
108 |
Correct |
98 ms |
83148 KB |
Output is correct |
109 |
Correct |
109 ms |
83148 KB |
Output is correct |
110 |
Correct |
106 ms |
36580 KB |
Output is correct |
111 |
Correct |
97 ms |
36560 KB |
Output is correct |
112 |
Correct |
101 ms |
36580 KB |
Output is correct |
113 |
Correct |
103 ms |
36472 KB |
Output is correct |
114 |
Correct |
120 ms |
36572 KB |
Output is correct |
115 |
Correct |
181 ms |
187344 KB |
Output is correct |
116 |
Correct |
199 ms |
187344 KB |
Output is correct |
117 |
Correct |
193 ms |
187340 KB |
Output is correct |
118 |
Correct |
174 ms |
187324 KB |
Output is correct |
119 |
Correct |
200 ms |
187164 KB |
Output is correct |
120 |
Correct |
118 ms |
36568 KB |
Output is correct |
121 |
Correct |
108 ms |
36048 KB |
Output is correct |
122 |
Correct |
107 ms |
36812 KB |
Output is correct |
123 |
Correct |
107 ms |
36564 KB |
Output is correct |
124 |
Correct |
120 ms |
112080 KB |
Output is correct |
125 |
Correct |
134 ms |
112072 KB |
Output is correct |
126 |
Correct |
128 ms |
112076 KB |
Output is correct |
127 |
Correct |
121 ms |
112080 KB |
Output is correct |
128 |
Correct |
45 ms |
29412 KB |
Output is correct |
129 |
Correct |
54 ms |
29408 KB |
Output is correct |
130 |
Correct |
42 ms |
29388 KB |
Output is correct |
131 |
Correct |
9 ms |
23900 KB |
Output is correct |