#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
const int MOD = 998244353;
const int maxN = 3000000;
int N;
set<int> closing[maxN];
string s;
pair<int, int> calc(int l, int r, int depth){
if(l == r){return {1, 1};}
int coma;
if(s[l + 4] == '?') coma = l + 5;
else{
coma = *closing[depth + 2].lower_bound(l); coma++;
}
pair<int, int> f = calc(l + 4, coma - 1, depth + 1);
pair<int, int> st = calc(coma + 1, r - 1, depth + 1);
if(s[l + 1] == 'i'){
return {f.first + st.first, min(f.second, st.second)};
}else{
return {min(f.first, st.first), f.second + st.second};
}
}
void solve(){
cin >> s;
int n = s.size();
int curr = 0;
N = 0;
for(int i = 0; i < n; i++){
if(s[i] == '?') N++;
else if(s[i] == '('){
curr++;
}else if(s[i] == ')'){
closing[curr].insert(i);
curr--;
}
}
pair<int, int> ans = calc(0, n - 1, 0);
ans.first = N - ans.first + 1;
cout << ans.first - ans.second + 1 << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("inpt.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
//int tt; cin >> tt;
int tt = 1;
for(int t = 1; t <= tt; t++){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
141100 KB |
Output is correct |
2 |
Correct |
67 ms |
141312 KB |
Output is correct |
3 |
Correct |
63 ms |
141156 KB |
Output is correct |
4 |
Correct |
61 ms |
141164 KB |
Output is correct |
5 |
Correct |
59 ms |
141116 KB |
Output is correct |
6 |
Correct |
61 ms |
141140 KB |
Output is correct |
7 |
Correct |
61 ms |
141172 KB |
Output is correct |
8 |
Correct |
61 ms |
141132 KB |
Output is correct |
9 |
Correct |
65 ms |
141200 KB |
Output is correct |
10 |
Correct |
60 ms |
141132 KB |
Output is correct |
11 |
Correct |
60 ms |
141136 KB |
Output is correct |
12 |
Correct |
61 ms |
141160 KB |
Output is correct |
13 |
Correct |
59 ms |
141128 KB |
Output is correct |
14 |
Correct |
64 ms |
141132 KB |
Output is correct |
15 |
Correct |
61 ms |
141128 KB |
Output is correct |
16 |
Correct |
60 ms |
141152 KB |
Output is correct |
17 |
Correct |
60 ms |
141108 KB |
Output is correct |
18 |
Correct |
58 ms |
141292 KB |
Output is correct |
19 |
Correct |
61 ms |
141144 KB |
Output is correct |
20 |
Correct |
60 ms |
141156 KB |
Output is correct |
21 |
Correct |
61 ms |
141120 KB |
Output is correct |
22 |
Correct |
61 ms |
141160 KB |
Output is correct |
23 |
Correct |
62 ms |
141168 KB |
Output is correct |
24 |
Correct |
61 ms |
141132 KB |
Output is correct |
25 |
Correct |
60 ms |
141188 KB |
Output is correct |
26 |
Correct |
61 ms |
141084 KB |
Output is correct |
27 |
Correct |
69 ms |
141132 KB |
Output is correct |
28 |
Correct |
63 ms |
141140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
141100 KB |
Output is correct |
2 |
Correct |
67 ms |
141312 KB |
Output is correct |
3 |
Correct |
63 ms |
141156 KB |
Output is correct |
4 |
Correct |
61 ms |
141164 KB |
Output is correct |
5 |
Correct |
59 ms |
141116 KB |
Output is correct |
6 |
Correct |
61 ms |
141140 KB |
Output is correct |
7 |
Correct |
61 ms |
141172 KB |
Output is correct |
8 |
Correct |
61 ms |
141132 KB |
Output is correct |
9 |
Correct |
65 ms |
141200 KB |
Output is correct |
10 |
Correct |
60 ms |
141132 KB |
Output is correct |
11 |
Correct |
60 ms |
141136 KB |
Output is correct |
12 |
Correct |
61 ms |
141160 KB |
Output is correct |
13 |
Correct |
59 ms |
141128 KB |
Output is correct |
14 |
Correct |
64 ms |
141132 KB |
Output is correct |
15 |
Correct |
61 ms |
141128 KB |
Output is correct |
16 |
Correct |
60 ms |
141152 KB |
Output is correct |
17 |
Correct |
60 ms |
141108 KB |
Output is correct |
18 |
Correct |
58 ms |
141292 KB |
Output is correct |
19 |
Correct |
61 ms |
141144 KB |
Output is correct |
20 |
Correct |
60 ms |
141156 KB |
Output is correct |
21 |
Correct |
61 ms |
141120 KB |
Output is correct |
22 |
Correct |
61 ms |
141160 KB |
Output is correct |
23 |
Correct |
62 ms |
141168 KB |
Output is correct |
24 |
Correct |
61 ms |
141132 KB |
Output is correct |
25 |
Correct |
60 ms |
141188 KB |
Output is correct |
26 |
Correct |
61 ms |
141084 KB |
Output is correct |
27 |
Correct |
69 ms |
141132 KB |
Output is correct |
28 |
Correct |
63 ms |
141140 KB |
Output is correct |
29 |
Correct |
63 ms |
141200 KB |
Output is correct |
30 |
Correct |
61 ms |
141116 KB |
Output is correct |
31 |
Correct |
61 ms |
141148 KB |
Output is correct |
32 |
Correct |
61 ms |
141080 KB |
Output is correct |
33 |
Correct |
61 ms |
141260 KB |
Output is correct |
34 |
Correct |
61 ms |
141228 KB |
Output is correct |
35 |
Correct |
62 ms |
141124 KB |
Output is correct |
36 |
Correct |
61 ms |
141132 KB |
Output is correct |
37 |
Correct |
61 ms |
141200 KB |
Output is correct |
38 |
Correct |
64 ms |
141144 KB |
Output is correct |
39 |
Correct |
62 ms |
141180 KB |
Output is correct |
40 |
Correct |
62 ms |
141132 KB |
Output is correct |
41 |
Correct |
62 ms |
141092 KB |
Output is correct |
42 |
Correct |
69 ms |
141120 KB |
Output is correct |
43 |
Correct |
63 ms |
141128 KB |
Output is correct |
44 |
Correct |
62 ms |
141124 KB |
Output is correct |
45 |
Correct |
66 ms |
141132 KB |
Output is correct |
46 |
Correct |
63 ms |
141192 KB |
Output is correct |
47 |
Correct |
67 ms |
141196 KB |
Output is correct |
48 |
Correct |
63 ms |
141104 KB |
Output is correct |
49 |
Correct |
64 ms |
141136 KB |
Output is correct |
50 |
Correct |
65 ms |
141156 KB |
Output is correct |
51 |
Correct |
65 ms |
141188 KB |
Output is correct |
52 |
Correct |
66 ms |
141100 KB |
Output is correct |
53 |
Correct |
68 ms |
141204 KB |
Output is correct |
54 |
Correct |
65 ms |
141208 KB |
Output is correct |
55 |
Correct |
67 ms |
141144 KB |
Output is correct |
56 |
Correct |
67 ms |
141288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
206 ms |
279080 KB |
Output is correct |
2 |
Correct |
209 ms |
279232 KB |
Output is correct |
3 |
Correct |
230 ms |
279224 KB |
Output is correct |
4 |
Correct |
202 ms |
280040 KB |
Output is correct |
5 |
Correct |
210 ms |
279788 KB |
Output is correct |
6 |
Correct |
207 ms |
279964 KB |
Output is correct |
7 |
Correct |
212 ms |
279576 KB |
Output is correct |
8 |
Correct |
208 ms |
279832 KB |
Output is correct |
9 |
Correct |
206 ms |
279192 KB |
Output is correct |
10 |
Correct |
200 ms |
279072 KB |
Output is correct |
11 |
Correct |
206 ms |
280132 KB |
Output is correct |
12 |
Correct |
203 ms |
279328 KB |
Output is correct |
13 |
Correct |
74 ms |
141124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
141100 KB |
Output is correct |
2 |
Correct |
67 ms |
141312 KB |
Output is correct |
3 |
Correct |
63 ms |
141156 KB |
Output is correct |
4 |
Correct |
61 ms |
141164 KB |
Output is correct |
5 |
Correct |
59 ms |
141116 KB |
Output is correct |
6 |
Correct |
61 ms |
141140 KB |
Output is correct |
7 |
Correct |
61 ms |
141172 KB |
Output is correct |
8 |
Correct |
61 ms |
141132 KB |
Output is correct |
9 |
Correct |
65 ms |
141200 KB |
Output is correct |
10 |
Correct |
60 ms |
141132 KB |
Output is correct |
11 |
Correct |
60 ms |
141136 KB |
Output is correct |
12 |
Correct |
61 ms |
141160 KB |
Output is correct |
13 |
Correct |
59 ms |
141128 KB |
Output is correct |
14 |
Correct |
64 ms |
141132 KB |
Output is correct |
15 |
Correct |
61 ms |
141128 KB |
Output is correct |
16 |
Correct |
60 ms |
141152 KB |
Output is correct |
17 |
Correct |
60 ms |
141108 KB |
Output is correct |
18 |
Correct |
58 ms |
141292 KB |
Output is correct |
19 |
Correct |
61 ms |
141144 KB |
Output is correct |
20 |
Correct |
60 ms |
141156 KB |
Output is correct |
21 |
Correct |
61 ms |
141120 KB |
Output is correct |
22 |
Correct |
61 ms |
141160 KB |
Output is correct |
23 |
Correct |
62 ms |
141168 KB |
Output is correct |
24 |
Correct |
61 ms |
141132 KB |
Output is correct |
25 |
Correct |
60 ms |
141188 KB |
Output is correct |
26 |
Correct |
61 ms |
141084 KB |
Output is correct |
27 |
Correct |
69 ms |
141132 KB |
Output is correct |
28 |
Correct |
63 ms |
141140 KB |
Output is correct |
29 |
Correct |
63 ms |
141200 KB |
Output is correct |
30 |
Correct |
61 ms |
141116 KB |
Output is correct |
31 |
Correct |
61 ms |
141148 KB |
Output is correct |
32 |
Correct |
61 ms |
141080 KB |
Output is correct |
33 |
Correct |
61 ms |
141260 KB |
Output is correct |
34 |
Correct |
61 ms |
141228 KB |
Output is correct |
35 |
Correct |
62 ms |
141124 KB |
Output is correct |
36 |
Correct |
61 ms |
141132 KB |
Output is correct |
37 |
Correct |
61 ms |
141200 KB |
Output is correct |
38 |
Correct |
64 ms |
141144 KB |
Output is correct |
39 |
Correct |
62 ms |
141180 KB |
Output is correct |
40 |
Correct |
62 ms |
141132 KB |
Output is correct |
41 |
Correct |
62 ms |
141092 KB |
Output is correct |
42 |
Correct |
69 ms |
141120 KB |
Output is correct |
43 |
Correct |
63 ms |
141128 KB |
Output is correct |
44 |
Correct |
62 ms |
141124 KB |
Output is correct |
45 |
Correct |
66 ms |
141132 KB |
Output is correct |
46 |
Correct |
63 ms |
141192 KB |
Output is correct |
47 |
Correct |
67 ms |
141196 KB |
Output is correct |
48 |
Correct |
63 ms |
141104 KB |
Output is correct |
49 |
Correct |
64 ms |
141136 KB |
Output is correct |
50 |
Correct |
65 ms |
141156 KB |
Output is correct |
51 |
Correct |
65 ms |
141188 KB |
Output is correct |
52 |
Correct |
66 ms |
141100 KB |
Output is correct |
53 |
Correct |
68 ms |
141204 KB |
Output is correct |
54 |
Correct |
65 ms |
141208 KB |
Output is correct |
55 |
Correct |
67 ms |
141144 KB |
Output is correct |
56 |
Correct |
67 ms |
141288 KB |
Output is correct |
57 |
Correct |
68 ms |
141156 KB |
Output is correct |
58 |
Correct |
65 ms |
141244 KB |
Output is correct |
59 |
Correct |
64 ms |
141236 KB |
Output is correct |
60 |
Correct |
66 ms |
141172 KB |
Output is correct |
61 |
Correct |
64 ms |
141192 KB |
Output is correct |
62 |
Correct |
66 ms |
141176 KB |
Output is correct |
63 |
Correct |
64 ms |
141160 KB |
Output is correct |
64 |
Correct |
64 ms |
141180 KB |
Output is correct |
65 |
Correct |
65 ms |
141200 KB |
Output is correct |
66 |
Correct |
65 ms |
141204 KB |
Output is correct |
67 |
Correct |
64 ms |
141252 KB |
Output is correct |
68 |
Correct |
65 ms |
141224 KB |
Output is correct |
69 |
Correct |
66 ms |
141200 KB |
Output is correct |
70 |
Correct |
65 ms |
141260 KB |
Output is correct |
71 |
Correct |
66 ms |
141256 KB |
Output is correct |
72 |
Correct |
65 ms |
141336 KB |
Output is correct |
73 |
Correct |
70 ms |
141276 KB |
Output is correct |
74 |
Correct |
66 ms |
141256 KB |
Output is correct |
75 |
Correct |
66 ms |
141276 KB |
Output is correct |
76 |
Correct |
70 ms |
141348 KB |
Output is correct |
77 |
Correct |
73 ms |
141208 KB |
Output is correct |
78 |
Correct |
66 ms |
141200 KB |
Output is correct |
79 |
Correct |
66 ms |
141132 KB |
Output is correct |
80 |
Correct |
65 ms |
141256 KB |
Output is correct |
81 |
Correct |
66 ms |
141260 KB |
Output is correct |
82 |
Correct |
66 ms |
141256 KB |
Output is correct |
83 |
Correct |
66 ms |
141216 KB |
Output is correct |
84 |
Correct |
66 ms |
141220 KB |
Output is correct |
85 |
Correct |
65 ms |
141112 KB |
Output is correct |
86 |
Correct |
64 ms |
141200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
141100 KB |
Output is correct |
2 |
Correct |
67 ms |
141312 KB |
Output is correct |
3 |
Correct |
63 ms |
141156 KB |
Output is correct |
4 |
Correct |
61 ms |
141164 KB |
Output is correct |
5 |
Correct |
59 ms |
141116 KB |
Output is correct |
6 |
Correct |
61 ms |
141140 KB |
Output is correct |
7 |
Correct |
61 ms |
141172 KB |
Output is correct |
8 |
Correct |
61 ms |
141132 KB |
Output is correct |
9 |
Correct |
65 ms |
141200 KB |
Output is correct |
10 |
Correct |
60 ms |
141132 KB |
Output is correct |
11 |
Correct |
60 ms |
141136 KB |
Output is correct |
12 |
Correct |
61 ms |
141160 KB |
Output is correct |
13 |
Correct |
59 ms |
141128 KB |
Output is correct |
14 |
Correct |
64 ms |
141132 KB |
Output is correct |
15 |
Correct |
61 ms |
141128 KB |
Output is correct |
16 |
Correct |
60 ms |
141152 KB |
Output is correct |
17 |
Correct |
60 ms |
141108 KB |
Output is correct |
18 |
Correct |
58 ms |
141292 KB |
Output is correct |
19 |
Correct |
61 ms |
141144 KB |
Output is correct |
20 |
Correct |
60 ms |
141156 KB |
Output is correct |
21 |
Correct |
61 ms |
141120 KB |
Output is correct |
22 |
Correct |
61 ms |
141160 KB |
Output is correct |
23 |
Correct |
62 ms |
141168 KB |
Output is correct |
24 |
Correct |
61 ms |
141132 KB |
Output is correct |
25 |
Correct |
60 ms |
141188 KB |
Output is correct |
26 |
Correct |
61 ms |
141084 KB |
Output is correct |
27 |
Correct |
69 ms |
141132 KB |
Output is correct |
28 |
Correct |
63 ms |
141140 KB |
Output is correct |
29 |
Correct |
63 ms |
141200 KB |
Output is correct |
30 |
Correct |
61 ms |
141116 KB |
Output is correct |
31 |
Correct |
61 ms |
141148 KB |
Output is correct |
32 |
Correct |
61 ms |
141080 KB |
Output is correct |
33 |
Correct |
61 ms |
141260 KB |
Output is correct |
34 |
Correct |
61 ms |
141228 KB |
Output is correct |
35 |
Correct |
62 ms |
141124 KB |
Output is correct |
36 |
Correct |
61 ms |
141132 KB |
Output is correct |
37 |
Correct |
61 ms |
141200 KB |
Output is correct |
38 |
Correct |
64 ms |
141144 KB |
Output is correct |
39 |
Correct |
62 ms |
141180 KB |
Output is correct |
40 |
Correct |
62 ms |
141132 KB |
Output is correct |
41 |
Correct |
62 ms |
141092 KB |
Output is correct |
42 |
Correct |
69 ms |
141120 KB |
Output is correct |
43 |
Correct |
63 ms |
141128 KB |
Output is correct |
44 |
Correct |
62 ms |
141124 KB |
Output is correct |
45 |
Correct |
66 ms |
141132 KB |
Output is correct |
46 |
Correct |
63 ms |
141192 KB |
Output is correct |
47 |
Correct |
67 ms |
141196 KB |
Output is correct |
48 |
Correct |
63 ms |
141104 KB |
Output is correct |
49 |
Correct |
64 ms |
141136 KB |
Output is correct |
50 |
Correct |
65 ms |
141156 KB |
Output is correct |
51 |
Correct |
65 ms |
141188 KB |
Output is correct |
52 |
Correct |
66 ms |
141100 KB |
Output is correct |
53 |
Correct |
68 ms |
141204 KB |
Output is correct |
54 |
Correct |
65 ms |
141208 KB |
Output is correct |
55 |
Correct |
67 ms |
141144 KB |
Output is correct |
56 |
Correct |
67 ms |
141288 KB |
Output is correct |
57 |
Correct |
206 ms |
279080 KB |
Output is correct |
58 |
Correct |
209 ms |
279232 KB |
Output is correct |
59 |
Correct |
230 ms |
279224 KB |
Output is correct |
60 |
Correct |
202 ms |
280040 KB |
Output is correct |
61 |
Correct |
210 ms |
279788 KB |
Output is correct |
62 |
Correct |
207 ms |
279964 KB |
Output is correct |
63 |
Correct |
212 ms |
279576 KB |
Output is correct |
64 |
Correct |
208 ms |
279832 KB |
Output is correct |
65 |
Correct |
206 ms |
279192 KB |
Output is correct |
66 |
Correct |
200 ms |
279072 KB |
Output is correct |
67 |
Correct |
206 ms |
280132 KB |
Output is correct |
68 |
Correct |
203 ms |
279328 KB |
Output is correct |
69 |
Correct |
74 ms |
141124 KB |
Output is correct |
70 |
Correct |
68 ms |
141156 KB |
Output is correct |
71 |
Correct |
65 ms |
141244 KB |
Output is correct |
72 |
Correct |
64 ms |
141236 KB |
Output is correct |
73 |
Correct |
66 ms |
141172 KB |
Output is correct |
74 |
Correct |
64 ms |
141192 KB |
Output is correct |
75 |
Correct |
66 ms |
141176 KB |
Output is correct |
76 |
Correct |
64 ms |
141160 KB |
Output is correct |
77 |
Correct |
64 ms |
141180 KB |
Output is correct |
78 |
Correct |
65 ms |
141200 KB |
Output is correct |
79 |
Correct |
65 ms |
141204 KB |
Output is correct |
80 |
Correct |
64 ms |
141252 KB |
Output is correct |
81 |
Correct |
65 ms |
141224 KB |
Output is correct |
82 |
Correct |
66 ms |
141200 KB |
Output is correct |
83 |
Correct |
65 ms |
141260 KB |
Output is correct |
84 |
Correct |
66 ms |
141256 KB |
Output is correct |
85 |
Correct |
65 ms |
141336 KB |
Output is correct |
86 |
Correct |
70 ms |
141276 KB |
Output is correct |
87 |
Correct |
66 ms |
141256 KB |
Output is correct |
88 |
Correct |
66 ms |
141276 KB |
Output is correct |
89 |
Correct |
70 ms |
141348 KB |
Output is correct |
90 |
Correct |
73 ms |
141208 KB |
Output is correct |
91 |
Correct |
66 ms |
141200 KB |
Output is correct |
92 |
Correct |
66 ms |
141132 KB |
Output is correct |
93 |
Correct |
65 ms |
141256 KB |
Output is correct |
94 |
Correct |
66 ms |
141260 KB |
Output is correct |
95 |
Correct |
66 ms |
141256 KB |
Output is correct |
96 |
Correct |
66 ms |
141216 KB |
Output is correct |
97 |
Correct |
66 ms |
141220 KB |
Output is correct |
98 |
Correct |
65 ms |
141112 KB |
Output is correct |
99 |
Correct |
64 ms |
141200 KB |
Output is correct |
100 |
Correct |
388 ms |
201700 KB |
Output is correct |
101 |
Correct |
380 ms |
201164 KB |
Output is correct |
102 |
Correct |
385 ms |
201204 KB |
Output is correct |
103 |
Correct |
392 ms |
201132 KB |
Output is correct |
104 |
Correct |
377 ms |
200712 KB |
Output is correct |
105 |
Correct |
205 ms |
227156 KB |
Output is correct |
106 |
Correct |
202 ms |
226860 KB |
Output is correct |
107 |
Correct |
199 ms |
226788 KB |
Output is correct |
108 |
Correct |
200 ms |
227396 KB |
Output is correct |
109 |
Correct |
196 ms |
227728 KB |
Output is correct |
110 |
Correct |
420 ms |
201792 KB |
Output is correct |
111 |
Correct |
426 ms |
201156 KB |
Output is correct |
112 |
Correct |
418 ms |
201540 KB |
Output is correct |
113 |
Correct |
449 ms |
201028 KB |
Output is correct |
114 |
Correct |
427 ms |
201240 KB |
Output is correct |
115 |
Correct |
216 ms |
279888 KB |
Output is correct |
116 |
Correct |
214 ms |
279420 KB |
Output is correct |
117 |
Correct |
215 ms |
279856 KB |
Output is correct |
118 |
Correct |
204 ms |
279284 KB |
Output is correct |
119 |
Correct |
208 ms |
279240 KB |
Output is correct |
120 |
Correct |
415 ms |
201640 KB |
Output is correct |
121 |
Correct |
413 ms |
201552 KB |
Output is correct |
122 |
Correct |
427 ms |
201308 KB |
Output is correct |
123 |
Correct |
426 ms |
201528 KB |
Output is correct |
124 |
Correct |
273 ms |
240832 KB |
Output is correct |
125 |
Correct |
267 ms |
240732 KB |
Output is correct |
126 |
Correct |
272 ms |
240408 KB |
Output is correct |
127 |
Correct |
280 ms |
240908 KB |
Output is correct |
128 |
Correct |
237 ms |
172900 KB |
Output is correct |
129 |
Correct |
234 ms |
172780 KB |
Output is correct |
130 |
Correct |
230 ms |
172980 KB |
Output is correct |
131 |
Correct |
62 ms |
141116 KB |
Output is correct |