#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
string s;
int n,cnt,com[20000005];
bool is_min[2000005];
vector<int> adj[2000005];
int build(int l, int r) {
int now=++cnt;
if (l!=r) {
adj[now].push_back(build(l+4,com[l+3]-1));
adj[now].push_back(build(com[l+3]+1,r-1));
if (s[l+1]=='i') is_min[now]=true;
}
return now;
}
pii dfs(int x) { //return min,max
if (adj[x].size()==0) return pii(1,n);
pii L=dfs(adj[x][0]), R=dfs(adj[x][1]), res;
if (is_min[x]) {
res.first=min(L.first,R.first);
res.second=L.second+R.second-n-1;
} else {
res.first=L.first+R.first;
res.second=max(L.second,R.second);
}
return res;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>s;
for (auto h : s) if (h=='?') ++n;
stack<int> st;
for (int i=0; i<s.size(); ++i) {
if (s[i]=='(') st.push(i);
else if (s[i]==',') com[st.top()]=i;
else if (s[i]==')') st.pop();
}
pii res=dfs(build(0,s.size()-1));
cout<<res.second-res.first+1;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i=0; i<s.size(); ++i) {
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47188 KB |
Output is correct |
2 |
Correct |
20 ms |
47188 KB |
Output is correct |
3 |
Correct |
22 ms |
47188 KB |
Output is correct |
4 |
Correct |
21 ms |
47300 KB |
Output is correct |
5 |
Correct |
22 ms |
47188 KB |
Output is correct |
6 |
Correct |
24 ms |
47316 KB |
Output is correct |
7 |
Correct |
21 ms |
47212 KB |
Output is correct |
8 |
Correct |
22 ms |
47288 KB |
Output is correct |
9 |
Correct |
22 ms |
47224 KB |
Output is correct |
10 |
Correct |
21 ms |
47188 KB |
Output is correct |
11 |
Correct |
22 ms |
47204 KB |
Output is correct |
12 |
Correct |
22 ms |
47208 KB |
Output is correct |
13 |
Correct |
23 ms |
47304 KB |
Output is correct |
14 |
Correct |
23 ms |
47244 KB |
Output is correct |
15 |
Correct |
23 ms |
47200 KB |
Output is correct |
16 |
Correct |
25 ms |
47188 KB |
Output is correct |
17 |
Correct |
22 ms |
47296 KB |
Output is correct |
18 |
Correct |
24 ms |
47252 KB |
Output is correct |
19 |
Correct |
22 ms |
47208 KB |
Output is correct |
20 |
Correct |
23 ms |
47256 KB |
Output is correct |
21 |
Correct |
23 ms |
47236 KB |
Output is correct |
22 |
Correct |
24 ms |
47212 KB |
Output is correct |
23 |
Correct |
24 ms |
47196 KB |
Output is correct |
24 |
Correct |
23 ms |
47188 KB |
Output is correct |
25 |
Correct |
25 ms |
47208 KB |
Output is correct |
26 |
Correct |
23 ms |
47232 KB |
Output is correct |
27 |
Correct |
23 ms |
47280 KB |
Output is correct |
28 |
Correct |
23 ms |
47188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47188 KB |
Output is correct |
2 |
Correct |
20 ms |
47188 KB |
Output is correct |
3 |
Correct |
22 ms |
47188 KB |
Output is correct |
4 |
Correct |
21 ms |
47300 KB |
Output is correct |
5 |
Correct |
22 ms |
47188 KB |
Output is correct |
6 |
Correct |
24 ms |
47316 KB |
Output is correct |
7 |
Correct |
21 ms |
47212 KB |
Output is correct |
8 |
Correct |
22 ms |
47288 KB |
Output is correct |
9 |
Correct |
22 ms |
47224 KB |
Output is correct |
10 |
Correct |
21 ms |
47188 KB |
Output is correct |
11 |
Correct |
22 ms |
47204 KB |
Output is correct |
12 |
Correct |
22 ms |
47208 KB |
Output is correct |
13 |
Correct |
23 ms |
47304 KB |
Output is correct |
14 |
Correct |
23 ms |
47244 KB |
Output is correct |
15 |
Correct |
23 ms |
47200 KB |
Output is correct |
16 |
Correct |
25 ms |
47188 KB |
Output is correct |
17 |
Correct |
22 ms |
47296 KB |
Output is correct |
18 |
Correct |
24 ms |
47252 KB |
Output is correct |
19 |
Correct |
22 ms |
47208 KB |
Output is correct |
20 |
Correct |
23 ms |
47256 KB |
Output is correct |
21 |
Correct |
23 ms |
47236 KB |
Output is correct |
22 |
Correct |
24 ms |
47212 KB |
Output is correct |
23 |
Correct |
24 ms |
47196 KB |
Output is correct |
24 |
Correct |
23 ms |
47188 KB |
Output is correct |
25 |
Correct |
25 ms |
47208 KB |
Output is correct |
26 |
Correct |
23 ms |
47232 KB |
Output is correct |
27 |
Correct |
23 ms |
47280 KB |
Output is correct |
28 |
Correct |
23 ms |
47188 KB |
Output is correct |
29 |
Correct |
23 ms |
47284 KB |
Output is correct |
30 |
Correct |
22 ms |
47212 KB |
Output is correct |
31 |
Correct |
22 ms |
47188 KB |
Output is correct |
32 |
Correct |
22 ms |
47176 KB |
Output is correct |
33 |
Correct |
22 ms |
47244 KB |
Output is correct |
34 |
Correct |
22 ms |
47232 KB |
Output is correct |
35 |
Correct |
22 ms |
47212 KB |
Output is correct |
36 |
Correct |
22 ms |
47188 KB |
Output is correct |
37 |
Correct |
23 ms |
47236 KB |
Output is correct |
38 |
Correct |
23 ms |
47184 KB |
Output is correct |
39 |
Correct |
23 ms |
47188 KB |
Output is correct |
40 |
Correct |
22 ms |
47300 KB |
Output is correct |
41 |
Correct |
22 ms |
47268 KB |
Output is correct |
42 |
Correct |
24 ms |
47300 KB |
Output is correct |
43 |
Correct |
23 ms |
47256 KB |
Output is correct |
44 |
Correct |
26 ms |
47188 KB |
Output is correct |
45 |
Correct |
27 ms |
47244 KB |
Output is correct |
46 |
Correct |
22 ms |
47208 KB |
Output is correct |
47 |
Correct |
21 ms |
47188 KB |
Output is correct |
48 |
Correct |
21 ms |
47296 KB |
Output is correct |
49 |
Correct |
22 ms |
47252 KB |
Output is correct |
50 |
Correct |
22 ms |
47220 KB |
Output is correct |
51 |
Correct |
23 ms |
47256 KB |
Output is correct |
52 |
Correct |
24 ms |
47296 KB |
Output is correct |
53 |
Correct |
24 ms |
47304 KB |
Output is correct |
54 |
Correct |
26 ms |
47280 KB |
Output is correct |
55 |
Correct |
23 ms |
47200 KB |
Output is correct |
56 |
Correct |
23 ms |
47292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
222 ms |
200940 KB |
Output is correct |
2 |
Correct |
234 ms |
199796 KB |
Output is correct |
3 |
Correct |
221 ms |
201140 KB |
Output is correct |
4 |
Correct |
226 ms |
201220 KB |
Output is correct |
5 |
Correct |
219 ms |
201380 KB |
Output is correct |
6 |
Correct |
218 ms |
201256 KB |
Output is correct |
7 |
Correct |
217 ms |
201184 KB |
Output is correct |
8 |
Correct |
243 ms |
201248 KB |
Output is correct |
9 |
Correct |
219 ms |
201268 KB |
Output is correct |
10 |
Correct |
218 ms |
201216 KB |
Output is correct |
11 |
Correct |
218 ms |
201340 KB |
Output is correct |
12 |
Correct |
217 ms |
201304 KB |
Output is correct |
13 |
Correct |
25 ms |
47216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47188 KB |
Output is correct |
2 |
Correct |
20 ms |
47188 KB |
Output is correct |
3 |
Correct |
22 ms |
47188 KB |
Output is correct |
4 |
Correct |
21 ms |
47300 KB |
Output is correct |
5 |
Correct |
22 ms |
47188 KB |
Output is correct |
6 |
Correct |
24 ms |
47316 KB |
Output is correct |
7 |
Correct |
21 ms |
47212 KB |
Output is correct |
8 |
Correct |
22 ms |
47288 KB |
Output is correct |
9 |
Correct |
22 ms |
47224 KB |
Output is correct |
10 |
Correct |
21 ms |
47188 KB |
Output is correct |
11 |
Correct |
22 ms |
47204 KB |
Output is correct |
12 |
Correct |
22 ms |
47208 KB |
Output is correct |
13 |
Correct |
23 ms |
47304 KB |
Output is correct |
14 |
Correct |
23 ms |
47244 KB |
Output is correct |
15 |
Correct |
23 ms |
47200 KB |
Output is correct |
16 |
Correct |
25 ms |
47188 KB |
Output is correct |
17 |
Correct |
22 ms |
47296 KB |
Output is correct |
18 |
Correct |
24 ms |
47252 KB |
Output is correct |
19 |
Correct |
22 ms |
47208 KB |
Output is correct |
20 |
Correct |
23 ms |
47256 KB |
Output is correct |
21 |
Correct |
23 ms |
47236 KB |
Output is correct |
22 |
Correct |
24 ms |
47212 KB |
Output is correct |
23 |
Correct |
24 ms |
47196 KB |
Output is correct |
24 |
Correct |
23 ms |
47188 KB |
Output is correct |
25 |
Correct |
25 ms |
47208 KB |
Output is correct |
26 |
Correct |
23 ms |
47232 KB |
Output is correct |
27 |
Correct |
23 ms |
47280 KB |
Output is correct |
28 |
Correct |
23 ms |
47188 KB |
Output is correct |
29 |
Correct |
23 ms |
47284 KB |
Output is correct |
30 |
Correct |
22 ms |
47212 KB |
Output is correct |
31 |
Correct |
22 ms |
47188 KB |
Output is correct |
32 |
Correct |
22 ms |
47176 KB |
Output is correct |
33 |
Correct |
22 ms |
47244 KB |
Output is correct |
34 |
Correct |
22 ms |
47232 KB |
Output is correct |
35 |
Correct |
22 ms |
47212 KB |
Output is correct |
36 |
Correct |
22 ms |
47188 KB |
Output is correct |
37 |
Correct |
23 ms |
47236 KB |
Output is correct |
38 |
Correct |
23 ms |
47184 KB |
Output is correct |
39 |
Correct |
23 ms |
47188 KB |
Output is correct |
40 |
Correct |
22 ms |
47300 KB |
Output is correct |
41 |
Correct |
22 ms |
47268 KB |
Output is correct |
42 |
Correct |
24 ms |
47300 KB |
Output is correct |
43 |
Correct |
23 ms |
47256 KB |
Output is correct |
44 |
Correct |
26 ms |
47188 KB |
Output is correct |
45 |
Correct |
27 ms |
47244 KB |
Output is correct |
46 |
Correct |
22 ms |
47208 KB |
Output is correct |
47 |
Correct |
21 ms |
47188 KB |
Output is correct |
48 |
Correct |
21 ms |
47296 KB |
Output is correct |
49 |
Correct |
22 ms |
47252 KB |
Output is correct |
50 |
Correct |
22 ms |
47220 KB |
Output is correct |
51 |
Correct |
23 ms |
47256 KB |
Output is correct |
52 |
Correct |
24 ms |
47296 KB |
Output is correct |
53 |
Correct |
24 ms |
47304 KB |
Output is correct |
54 |
Correct |
26 ms |
47280 KB |
Output is correct |
55 |
Correct |
23 ms |
47200 KB |
Output is correct |
56 |
Correct |
23 ms |
47292 KB |
Output is correct |
57 |
Correct |
22 ms |
47328 KB |
Output is correct |
58 |
Correct |
26 ms |
47308 KB |
Output is correct |
59 |
Correct |
24 ms |
47380 KB |
Output is correct |
60 |
Correct |
23 ms |
47304 KB |
Output is correct |
61 |
Correct |
26 ms |
47316 KB |
Output is correct |
62 |
Correct |
20 ms |
47348 KB |
Output is correct |
63 |
Correct |
20 ms |
47284 KB |
Output is correct |
64 |
Correct |
20 ms |
47296 KB |
Output is correct |
65 |
Correct |
20 ms |
47356 KB |
Output is correct |
66 |
Correct |
23 ms |
47296 KB |
Output is correct |
67 |
Correct |
21 ms |
47260 KB |
Output is correct |
68 |
Correct |
20 ms |
47308 KB |
Output is correct |
69 |
Correct |
19 ms |
47312 KB |
Output is correct |
70 |
Correct |
19 ms |
47364 KB |
Output is correct |
71 |
Correct |
20 ms |
47296 KB |
Output is correct |
72 |
Correct |
26 ms |
47464 KB |
Output is correct |
73 |
Correct |
23 ms |
47436 KB |
Output is correct |
74 |
Correct |
25 ms |
47412 KB |
Output is correct |
75 |
Correct |
25 ms |
47412 KB |
Output is correct |
76 |
Correct |
24 ms |
47360 KB |
Output is correct |
77 |
Correct |
26 ms |
47364 KB |
Output is correct |
78 |
Correct |
28 ms |
47284 KB |
Output is correct |
79 |
Correct |
23 ms |
47296 KB |
Output is correct |
80 |
Correct |
24 ms |
47300 KB |
Output is correct |
81 |
Correct |
23 ms |
47280 KB |
Output is correct |
82 |
Correct |
25 ms |
47436 KB |
Output is correct |
83 |
Correct |
29 ms |
47220 KB |
Output is correct |
84 |
Correct |
24 ms |
47220 KB |
Output is correct |
85 |
Correct |
25 ms |
47272 KB |
Output is correct |
86 |
Correct |
27 ms |
47288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
47188 KB |
Output is correct |
2 |
Correct |
20 ms |
47188 KB |
Output is correct |
3 |
Correct |
22 ms |
47188 KB |
Output is correct |
4 |
Correct |
21 ms |
47300 KB |
Output is correct |
5 |
Correct |
22 ms |
47188 KB |
Output is correct |
6 |
Correct |
24 ms |
47316 KB |
Output is correct |
7 |
Correct |
21 ms |
47212 KB |
Output is correct |
8 |
Correct |
22 ms |
47288 KB |
Output is correct |
9 |
Correct |
22 ms |
47224 KB |
Output is correct |
10 |
Correct |
21 ms |
47188 KB |
Output is correct |
11 |
Correct |
22 ms |
47204 KB |
Output is correct |
12 |
Correct |
22 ms |
47208 KB |
Output is correct |
13 |
Correct |
23 ms |
47304 KB |
Output is correct |
14 |
Correct |
23 ms |
47244 KB |
Output is correct |
15 |
Correct |
23 ms |
47200 KB |
Output is correct |
16 |
Correct |
25 ms |
47188 KB |
Output is correct |
17 |
Correct |
22 ms |
47296 KB |
Output is correct |
18 |
Correct |
24 ms |
47252 KB |
Output is correct |
19 |
Correct |
22 ms |
47208 KB |
Output is correct |
20 |
Correct |
23 ms |
47256 KB |
Output is correct |
21 |
Correct |
23 ms |
47236 KB |
Output is correct |
22 |
Correct |
24 ms |
47212 KB |
Output is correct |
23 |
Correct |
24 ms |
47196 KB |
Output is correct |
24 |
Correct |
23 ms |
47188 KB |
Output is correct |
25 |
Correct |
25 ms |
47208 KB |
Output is correct |
26 |
Correct |
23 ms |
47232 KB |
Output is correct |
27 |
Correct |
23 ms |
47280 KB |
Output is correct |
28 |
Correct |
23 ms |
47188 KB |
Output is correct |
29 |
Correct |
23 ms |
47284 KB |
Output is correct |
30 |
Correct |
22 ms |
47212 KB |
Output is correct |
31 |
Correct |
22 ms |
47188 KB |
Output is correct |
32 |
Correct |
22 ms |
47176 KB |
Output is correct |
33 |
Correct |
22 ms |
47244 KB |
Output is correct |
34 |
Correct |
22 ms |
47232 KB |
Output is correct |
35 |
Correct |
22 ms |
47212 KB |
Output is correct |
36 |
Correct |
22 ms |
47188 KB |
Output is correct |
37 |
Correct |
23 ms |
47236 KB |
Output is correct |
38 |
Correct |
23 ms |
47184 KB |
Output is correct |
39 |
Correct |
23 ms |
47188 KB |
Output is correct |
40 |
Correct |
22 ms |
47300 KB |
Output is correct |
41 |
Correct |
22 ms |
47268 KB |
Output is correct |
42 |
Correct |
24 ms |
47300 KB |
Output is correct |
43 |
Correct |
23 ms |
47256 KB |
Output is correct |
44 |
Correct |
26 ms |
47188 KB |
Output is correct |
45 |
Correct |
27 ms |
47244 KB |
Output is correct |
46 |
Correct |
22 ms |
47208 KB |
Output is correct |
47 |
Correct |
21 ms |
47188 KB |
Output is correct |
48 |
Correct |
21 ms |
47296 KB |
Output is correct |
49 |
Correct |
22 ms |
47252 KB |
Output is correct |
50 |
Correct |
22 ms |
47220 KB |
Output is correct |
51 |
Correct |
23 ms |
47256 KB |
Output is correct |
52 |
Correct |
24 ms |
47296 KB |
Output is correct |
53 |
Correct |
24 ms |
47304 KB |
Output is correct |
54 |
Correct |
26 ms |
47280 KB |
Output is correct |
55 |
Correct |
23 ms |
47200 KB |
Output is correct |
56 |
Correct |
23 ms |
47292 KB |
Output is correct |
57 |
Correct |
222 ms |
200940 KB |
Output is correct |
58 |
Correct |
234 ms |
199796 KB |
Output is correct |
59 |
Correct |
221 ms |
201140 KB |
Output is correct |
60 |
Correct |
226 ms |
201220 KB |
Output is correct |
61 |
Correct |
219 ms |
201380 KB |
Output is correct |
62 |
Correct |
218 ms |
201256 KB |
Output is correct |
63 |
Correct |
217 ms |
201184 KB |
Output is correct |
64 |
Correct |
243 ms |
201248 KB |
Output is correct |
65 |
Correct |
219 ms |
201268 KB |
Output is correct |
66 |
Correct |
218 ms |
201216 KB |
Output is correct |
67 |
Correct |
218 ms |
201340 KB |
Output is correct |
68 |
Correct |
217 ms |
201304 KB |
Output is correct |
69 |
Correct |
25 ms |
47216 KB |
Output is correct |
70 |
Correct |
22 ms |
47328 KB |
Output is correct |
71 |
Correct |
26 ms |
47308 KB |
Output is correct |
72 |
Correct |
24 ms |
47380 KB |
Output is correct |
73 |
Correct |
23 ms |
47304 KB |
Output is correct |
74 |
Correct |
26 ms |
47316 KB |
Output is correct |
75 |
Correct |
20 ms |
47348 KB |
Output is correct |
76 |
Correct |
20 ms |
47284 KB |
Output is correct |
77 |
Correct |
20 ms |
47296 KB |
Output is correct |
78 |
Correct |
20 ms |
47356 KB |
Output is correct |
79 |
Correct |
23 ms |
47296 KB |
Output is correct |
80 |
Correct |
21 ms |
47260 KB |
Output is correct |
81 |
Correct |
20 ms |
47308 KB |
Output is correct |
82 |
Correct |
19 ms |
47312 KB |
Output is correct |
83 |
Correct |
19 ms |
47364 KB |
Output is correct |
84 |
Correct |
20 ms |
47296 KB |
Output is correct |
85 |
Correct |
26 ms |
47464 KB |
Output is correct |
86 |
Correct |
23 ms |
47436 KB |
Output is correct |
87 |
Correct |
25 ms |
47412 KB |
Output is correct |
88 |
Correct |
25 ms |
47412 KB |
Output is correct |
89 |
Correct |
24 ms |
47360 KB |
Output is correct |
90 |
Correct |
26 ms |
47364 KB |
Output is correct |
91 |
Correct |
28 ms |
47284 KB |
Output is correct |
92 |
Correct |
23 ms |
47296 KB |
Output is correct |
93 |
Correct |
24 ms |
47300 KB |
Output is correct |
94 |
Correct |
23 ms |
47280 KB |
Output is correct |
95 |
Correct |
25 ms |
47436 KB |
Output is correct |
96 |
Correct |
29 ms |
47220 KB |
Output is correct |
97 |
Correct |
24 ms |
47220 KB |
Output is correct |
98 |
Correct |
25 ms |
47272 KB |
Output is correct |
99 |
Correct |
27 ms |
47288 KB |
Output is correct |
100 |
Correct |
179 ms |
115452 KB |
Output is correct |
101 |
Correct |
184 ms |
115516 KB |
Output is correct |
102 |
Correct |
195 ms |
115460 KB |
Output is correct |
103 |
Correct |
175 ms |
115492 KB |
Output is correct |
104 |
Correct |
175 ms |
115516 KB |
Output is correct |
105 |
Correct |
202 ms |
146820 KB |
Output is correct |
106 |
Correct |
197 ms |
146820 KB |
Output is correct |
107 |
Correct |
231 ms |
146812 KB |
Output is correct |
108 |
Correct |
192 ms |
146756 KB |
Output is correct |
109 |
Correct |
206 ms |
146904 KB |
Output is correct |
110 |
Correct |
177 ms |
115524 KB |
Output is correct |
111 |
Correct |
203 ms |
115460 KB |
Output is correct |
112 |
Correct |
179 ms |
115524 KB |
Output is correct |
113 |
Correct |
171 ms |
115480 KB |
Output is correct |
114 |
Correct |
179 ms |
115472 KB |
Output is correct |
115 |
Correct |
233 ms |
201200 KB |
Output is correct |
116 |
Correct |
230 ms |
201132 KB |
Output is correct |
117 |
Correct |
223 ms |
201236 KB |
Output is correct |
118 |
Correct |
235 ms |
201164 KB |
Output is correct |
119 |
Correct |
239 ms |
201156 KB |
Output is correct |
120 |
Correct |
194 ms |
115532 KB |
Output is correct |
121 |
Correct |
185 ms |
113556 KB |
Output is correct |
122 |
Correct |
181 ms |
115544 KB |
Output is correct |
123 |
Correct |
183 ms |
115468 KB |
Output is correct |
124 |
Correct |
206 ms |
159616 KB |
Output is correct |
125 |
Correct |
176 ms |
160576 KB |
Output is correct |
126 |
Correct |
173 ms |
159540 KB |
Output is correct |
127 |
Correct |
183 ms |
160580 KB |
Output is correct |
128 |
Correct |
97 ms |
83028 KB |
Output is correct |
129 |
Correct |
96 ms |
83000 KB |
Output is correct |
130 |
Correct |
88 ms |
82964 KB |
Output is correct |
131 |
Correct |
24 ms |
47188 KB |
Output is correct |