#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)2e6 + 10;
int typ[N];
vector<int> nex[N];
/*
0 - min
1 - max
2 - ?
*/
int cnt[N];
int lf[N];
int rf[N];
/*
void dfs0(int u){
cout << u << " -> ";
if(typ[u] == 0){
cout << "min (";
}
else if(typ[u] == 1){
cout << "max (";
}
else{
cout << " ? ";
}
for(auto x : nex[u]){
cout << x << " ";
}
cout << ")\n";
for(auto x : nex[u]){
dfs0(x);
}
}
*/
void calc(int u){
if(typ[u] == 2){
cnt[u] = 1;
lf[u]=1;
rf[u]=1;
}
else{
for(auto x : nex[u]){
calc(x);
cnt[u] += cnt[x];
}
if(typ[u] == 0){
lf[u]=min(lf[nex[u][0]], lf[nex[u][1]]);
rf[u]=rf[nex[u][0]]+rf[nex[u][1]]-1;
}
else{
rf[u]=cnt[u]-min(cnt[nex[u][0]]-rf[nex[u][0]], cnt[nex[u][1]]-rf[nex[u][1]]);
lf[u]=lf[nex[u][0]]+lf[nex[u][1]];
}
}
}
int main(){
fastIO;
string s;
cin >> s;
if(s.size() == 1){
cout << "1\n";
return 0;
}
int id = 0;
vector<int> stek;
int cur;
int las = -1;
for(char x : s){
if(x == '('){
cur = id;
id ++ ;
if(!stek.empty()){
nex[stek.back()].push_back(cur);
}
typ[cur] = las;
stek.push_back(cur);
}
else if(x == ')'){
stek.pop_back();
}
else if(x == '?'){
cur = id;
id ++ ;
typ[cur] = 2;
nex[stek.back()].push_back(cur);
}
else{
if('a' <= x && x <= 'z'){
if(x == 'i'){
las = 0;
}
else if(x == 'x'){
las = 1;
}
else{
continue;
}
}
}
}
calc(0);
cout << rf[0]-lf[0]+1 << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
47316 KB |
Output is correct |
2 |
Correct |
24 ms |
47300 KB |
Output is correct |
3 |
Correct |
22 ms |
47320 KB |
Output is correct |
4 |
Correct |
23 ms |
47316 KB |
Output is correct |
5 |
Correct |
23 ms |
47228 KB |
Output is correct |
6 |
Correct |
26 ms |
47304 KB |
Output is correct |
7 |
Correct |
24 ms |
47308 KB |
Output is correct |
8 |
Correct |
26 ms |
47216 KB |
Output is correct |
9 |
Correct |
21 ms |
47328 KB |
Output is correct |
10 |
Correct |
23 ms |
47204 KB |
Output is correct |
11 |
Correct |
21 ms |
47188 KB |
Output is correct |
12 |
Correct |
24 ms |
47312 KB |
Output is correct |
13 |
Correct |
22 ms |
47316 KB |
Output is correct |
14 |
Correct |
20 ms |
47316 KB |
Output is correct |
15 |
Correct |
18 ms |
47304 KB |
Output is correct |
16 |
Correct |
19 ms |
47312 KB |
Output is correct |
17 |
Correct |
19 ms |
47316 KB |
Output is correct |
18 |
Correct |
20 ms |
47228 KB |
Output is correct |
19 |
Correct |
19 ms |
47320 KB |
Output is correct |
20 |
Correct |
20 ms |
47312 KB |
Output is correct |
21 |
Correct |
22 ms |
47300 KB |
Output is correct |
22 |
Correct |
19 ms |
47300 KB |
Output is correct |
23 |
Correct |
20 ms |
47272 KB |
Output is correct |
24 |
Correct |
20 ms |
47232 KB |
Output is correct |
25 |
Correct |
19 ms |
47228 KB |
Output is correct |
26 |
Correct |
20 ms |
47272 KB |
Output is correct |
27 |
Correct |
22 ms |
47248 KB |
Output is correct |
28 |
Correct |
18 ms |
47316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
47316 KB |
Output is correct |
2 |
Correct |
24 ms |
47300 KB |
Output is correct |
3 |
Correct |
22 ms |
47320 KB |
Output is correct |
4 |
Correct |
23 ms |
47316 KB |
Output is correct |
5 |
Correct |
23 ms |
47228 KB |
Output is correct |
6 |
Correct |
26 ms |
47304 KB |
Output is correct |
7 |
Correct |
24 ms |
47308 KB |
Output is correct |
8 |
Correct |
26 ms |
47216 KB |
Output is correct |
9 |
Correct |
21 ms |
47328 KB |
Output is correct |
10 |
Correct |
23 ms |
47204 KB |
Output is correct |
11 |
Correct |
21 ms |
47188 KB |
Output is correct |
12 |
Correct |
24 ms |
47312 KB |
Output is correct |
13 |
Correct |
22 ms |
47316 KB |
Output is correct |
14 |
Correct |
20 ms |
47316 KB |
Output is correct |
15 |
Correct |
18 ms |
47304 KB |
Output is correct |
16 |
Correct |
19 ms |
47312 KB |
Output is correct |
17 |
Correct |
19 ms |
47316 KB |
Output is correct |
18 |
Correct |
20 ms |
47228 KB |
Output is correct |
19 |
Correct |
19 ms |
47320 KB |
Output is correct |
20 |
Correct |
20 ms |
47312 KB |
Output is correct |
21 |
Correct |
22 ms |
47300 KB |
Output is correct |
22 |
Correct |
19 ms |
47300 KB |
Output is correct |
23 |
Correct |
20 ms |
47272 KB |
Output is correct |
24 |
Correct |
20 ms |
47232 KB |
Output is correct |
25 |
Correct |
19 ms |
47228 KB |
Output is correct |
26 |
Correct |
20 ms |
47272 KB |
Output is correct |
27 |
Correct |
22 ms |
47248 KB |
Output is correct |
28 |
Correct |
18 ms |
47316 KB |
Output is correct |
29 |
Correct |
21 ms |
47240 KB |
Output is correct |
30 |
Correct |
20 ms |
47212 KB |
Output is correct |
31 |
Correct |
20 ms |
47316 KB |
Output is correct |
32 |
Correct |
20 ms |
47304 KB |
Output is correct |
33 |
Correct |
20 ms |
47196 KB |
Output is correct |
34 |
Correct |
28 ms |
47236 KB |
Output is correct |
35 |
Correct |
23 ms |
47296 KB |
Output is correct |
36 |
Correct |
21 ms |
47292 KB |
Output is correct |
37 |
Correct |
21 ms |
47228 KB |
Output is correct |
38 |
Correct |
21 ms |
47308 KB |
Output is correct |
39 |
Correct |
20 ms |
47292 KB |
Output is correct |
40 |
Correct |
20 ms |
47304 KB |
Output is correct |
41 |
Correct |
21 ms |
47204 KB |
Output is correct |
42 |
Correct |
22 ms |
47288 KB |
Output is correct |
43 |
Correct |
20 ms |
47256 KB |
Output is correct |
44 |
Correct |
25 ms |
47224 KB |
Output is correct |
45 |
Correct |
23 ms |
47288 KB |
Output is correct |
46 |
Correct |
23 ms |
47220 KB |
Output is correct |
47 |
Correct |
23 ms |
47304 KB |
Output is correct |
48 |
Correct |
22 ms |
47316 KB |
Output is correct |
49 |
Correct |
22 ms |
47296 KB |
Output is correct |
50 |
Correct |
24 ms |
47228 KB |
Output is correct |
51 |
Correct |
28 ms |
47316 KB |
Output is correct |
52 |
Correct |
29 ms |
47288 KB |
Output is correct |
53 |
Correct |
24 ms |
47288 KB |
Output is correct |
54 |
Correct |
26 ms |
47404 KB |
Output is correct |
55 |
Correct |
27 ms |
47308 KB |
Output is correct |
56 |
Correct |
24 ms |
47308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
194 ms |
205716 KB |
Output is correct |
2 |
Correct |
190 ms |
205748 KB |
Output is correct |
3 |
Correct |
230 ms |
205732 KB |
Output is correct |
4 |
Correct |
197 ms |
205688 KB |
Output is correct |
5 |
Correct |
230 ms |
205740 KB |
Output is correct |
6 |
Correct |
190 ms |
205676 KB |
Output is correct |
7 |
Correct |
208 ms |
205692 KB |
Output is correct |
8 |
Correct |
212 ms |
205744 KB |
Output is correct |
9 |
Correct |
239 ms |
205760 KB |
Output is correct |
10 |
Correct |
217 ms |
205748 KB |
Output is correct |
11 |
Correct |
205 ms |
205788 KB |
Output is correct |
12 |
Correct |
201 ms |
205756 KB |
Output is correct |
13 |
Correct |
23 ms |
47316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
47316 KB |
Output is correct |
2 |
Correct |
24 ms |
47300 KB |
Output is correct |
3 |
Correct |
22 ms |
47320 KB |
Output is correct |
4 |
Correct |
23 ms |
47316 KB |
Output is correct |
5 |
Correct |
23 ms |
47228 KB |
Output is correct |
6 |
Correct |
26 ms |
47304 KB |
Output is correct |
7 |
Correct |
24 ms |
47308 KB |
Output is correct |
8 |
Correct |
26 ms |
47216 KB |
Output is correct |
9 |
Correct |
21 ms |
47328 KB |
Output is correct |
10 |
Correct |
23 ms |
47204 KB |
Output is correct |
11 |
Correct |
21 ms |
47188 KB |
Output is correct |
12 |
Correct |
24 ms |
47312 KB |
Output is correct |
13 |
Correct |
22 ms |
47316 KB |
Output is correct |
14 |
Correct |
20 ms |
47316 KB |
Output is correct |
15 |
Correct |
18 ms |
47304 KB |
Output is correct |
16 |
Correct |
19 ms |
47312 KB |
Output is correct |
17 |
Correct |
19 ms |
47316 KB |
Output is correct |
18 |
Correct |
20 ms |
47228 KB |
Output is correct |
19 |
Correct |
19 ms |
47320 KB |
Output is correct |
20 |
Correct |
20 ms |
47312 KB |
Output is correct |
21 |
Correct |
22 ms |
47300 KB |
Output is correct |
22 |
Correct |
19 ms |
47300 KB |
Output is correct |
23 |
Correct |
20 ms |
47272 KB |
Output is correct |
24 |
Correct |
20 ms |
47232 KB |
Output is correct |
25 |
Correct |
19 ms |
47228 KB |
Output is correct |
26 |
Correct |
20 ms |
47272 KB |
Output is correct |
27 |
Correct |
22 ms |
47248 KB |
Output is correct |
28 |
Correct |
18 ms |
47316 KB |
Output is correct |
29 |
Correct |
21 ms |
47240 KB |
Output is correct |
30 |
Correct |
20 ms |
47212 KB |
Output is correct |
31 |
Correct |
20 ms |
47316 KB |
Output is correct |
32 |
Correct |
20 ms |
47304 KB |
Output is correct |
33 |
Correct |
20 ms |
47196 KB |
Output is correct |
34 |
Correct |
28 ms |
47236 KB |
Output is correct |
35 |
Correct |
23 ms |
47296 KB |
Output is correct |
36 |
Correct |
21 ms |
47292 KB |
Output is correct |
37 |
Correct |
21 ms |
47228 KB |
Output is correct |
38 |
Correct |
21 ms |
47308 KB |
Output is correct |
39 |
Correct |
20 ms |
47292 KB |
Output is correct |
40 |
Correct |
20 ms |
47304 KB |
Output is correct |
41 |
Correct |
21 ms |
47204 KB |
Output is correct |
42 |
Correct |
22 ms |
47288 KB |
Output is correct |
43 |
Correct |
20 ms |
47256 KB |
Output is correct |
44 |
Correct |
25 ms |
47224 KB |
Output is correct |
45 |
Correct |
23 ms |
47288 KB |
Output is correct |
46 |
Correct |
23 ms |
47220 KB |
Output is correct |
47 |
Correct |
23 ms |
47304 KB |
Output is correct |
48 |
Correct |
22 ms |
47316 KB |
Output is correct |
49 |
Correct |
22 ms |
47296 KB |
Output is correct |
50 |
Correct |
24 ms |
47228 KB |
Output is correct |
51 |
Correct |
28 ms |
47316 KB |
Output is correct |
52 |
Correct |
29 ms |
47288 KB |
Output is correct |
53 |
Correct |
24 ms |
47288 KB |
Output is correct |
54 |
Correct |
26 ms |
47404 KB |
Output is correct |
55 |
Correct |
27 ms |
47308 KB |
Output is correct |
56 |
Correct |
24 ms |
47308 KB |
Output is correct |
57 |
Correct |
23 ms |
47316 KB |
Output is correct |
58 |
Correct |
24 ms |
47408 KB |
Output is correct |
59 |
Correct |
27 ms |
47280 KB |
Output is correct |
60 |
Correct |
23 ms |
47316 KB |
Output is correct |
61 |
Correct |
25 ms |
47380 KB |
Output is correct |
62 |
Correct |
24 ms |
47400 KB |
Output is correct |
63 |
Correct |
25 ms |
47304 KB |
Output is correct |
64 |
Correct |
26 ms |
47312 KB |
Output is correct |
65 |
Correct |
24 ms |
47300 KB |
Output is correct |
66 |
Correct |
26 ms |
47420 KB |
Output is correct |
67 |
Correct |
23 ms |
47292 KB |
Output is correct |
68 |
Correct |
29 ms |
47284 KB |
Output is correct |
69 |
Correct |
23 ms |
47296 KB |
Output is correct |
70 |
Correct |
24 ms |
47360 KB |
Output is correct |
71 |
Correct |
26 ms |
47316 KB |
Output is correct |
72 |
Correct |
23 ms |
47436 KB |
Output is correct |
73 |
Correct |
23 ms |
47364 KB |
Output is correct |
74 |
Correct |
23 ms |
47444 KB |
Output is correct |
75 |
Correct |
23 ms |
47440 KB |
Output is correct |
76 |
Correct |
23 ms |
47364 KB |
Output is correct |
77 |
Correct |
24 ms |
47316 KB |
Output is correct |
78 |
Correct |
27 ms |
47384 KB |
Output is correct |
79 |
Correct |
22 ms |
47316 KB |
Output is correct |
80 |
Correct |
22 ms |
47312 KB |
Output is correct |
81 |
Correct |
23 ms |
47380 KB |
Output is correct |
82 |
Correct |
28 ms |
47308 KB |
Output is correct |
83 |
Correct |
23 ms |
47280 KB |
Output is correct |
84 |
Correct |
22 ms |
47316 KB |
Output is correct |
85 |
Correct |
23 ms |
47316 KB |
Output is correct |
86 |
Correct |
23 ms |
47268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
47316 KB |
Output is correct |
2 |
Correct |
24 ms |
47300 KB |
Output is correct |
3 |
Correct |
22 ms |
47320 KB |
Output is correct |
4 |
Correct |
23 ms |
47316 KB |
Output is correct |
5 |
Correct |
23 ms |
47228 KB |
Output is correct |
6 |
Correct |
26 ms |
47304 KB |
Output is correct |
7 |
Correct |
24 ms |
47308 KB |
Output is correct |
8 |
Correct |
26 ms |
47216 KB |
Output is correct |
9 |
Correct |
21 ms |
47328 KB |
Output is correct |
10 |
Correct |
23 ms |
47204 KB |
Output is correct |
11 |
Correct |
21 ms |
47188 KB |
Output is correct |
12 |
Correct |
24 ms |
47312 KB |
Output is correct |
13 |
Correct |
22 ms |
47316 KB |
Output is correct |
14 |
Correct |
20 ms |
47316 KB |
Output is correct |
15 |
Correct |
18 ms |
47304 KB |
Output is correct |
16 |
Correct |
19 ms |
47312 KB |
Output is correct |
17 |
Correct |
19 ms |
47316 KB |
Output is correct |
18 |
Correct |
20 ms |
47228 KB |
Output is correct |
19 |
Correct |
19 ms |
47320 KB |
Output is correct |
20 |
Correct |
20 ms |
47312 KB |
Output is correct |
21 |
Correct |
22 ms |
47300 KB |
Output is correct |
22 |
Correct |
19 ms |
47300 KB |
Output is correct |
23 |
Correct |
20 ms |
47272 KB |
Output is correct |
24 |
Correct |
20 ms |
47232 KB |
Output is correct |
25 |
Correct |
19 ms |
47228 KB |
Output is correct |
26 |
Correct |
20 ms |
47272 KB |
Output is correct |
27 |
Correct |
22 ms |
47248 KB |
Output is correct |
28 |
Correct |
18 ms |
47316 KB |
Output is correct |
29 |
Correct |
21 ms |
47240 KB |
Output is correct |
30 |
Correct |
20 ms |
47212 KB |
Output is correct |
31 |
Correct |
20 ms |
47316 KB |
Output is correct |
32 |
Correct |
20 ms |
47304 KB |
Output is correct |
33 |
Correct |
20 ms |
47196 KB |
Output is correct |
34 |
Correct |
28 ms |
47236 KB |
Output is correct |
35 |
Correct |
23 ms |
47296 KB |
Output is correct |
36 |
Correct |
21 ms |
47292 KB |
Output is correct |
37 |
Correct |
21 ms |
47228 KB |
Output is correct |
38 |
Correct |
21 ms |
47308 KB |
Output is correct |
39 |
Correct |
20 ms |
47292 KB |
Output is correct |
40 |
Correct |
20 ms |
47304 KB |
Output is correct |
41 |
Correct |
21 ms |
47204 KB |
Output is correct |
42 |
Correct |
22 ms |
47288 KB |
Output is correct |
43 |
Correct |
20 ms |
47256 KB |
Output is correct |
44 |
Correct |
25 ms |
47224 KB |
Output is correct |
45 |
Correct |
23 ms |
47288 KB |
Output is correct |
46 |
Correct |
23 ms |
47220 KB |
Output is correct |
47 |
Correct |
23 ms |
47304 KB |
Output is correct |
48 |
Correct |
22 ms |
47316 KB |
Output is correct |
49 |
Correct |
22 ms |
47296 KB |
Output is correct |
50 |
Correct |
24 ms |
47228 KB |
Output is correct |
51 |
Correct |
28 ms |
47316 KB |
Output is correct |
52 |
Correct |
29 ms |
47288 KB |
Output is correct |
53 |
Correct |
24 ms |
47288 KB |
Output is correct |
54 |
Correct |
26 ms |
47404 KB |
Output is correct |
55 |
Correct |
27 ms |
47308 KB |
Output is correct |
56 |
Correct |
24 ms |
47308 KB |
Output is correct |
57 |
Correct |
194 ms |
205716 KB |
Output is correct |
58 |
Correct |
190 ms |
205748 KB |
Output is correct |
59 |
Correct |
230 ms |
205732 KB |
Output is correct |
60 |
Correct |
197 ms |
205688 KB |
Output is correct |
61 |
Correct |
230 ms |
205740 KB |
Output is correct |
62 |
Correct |
190 ms |
205676 KB |
Output is correct |
63 |
Correct |
208 ms |
205692 KB |
Output is correct |
64 |
Correct |
212 ms |
205744 KB |
Output is correct |
65 |
Correct |
239 ms |
205760 KB |
Output is correct |
66 |
Correct |
217 ms |
205748 KB |
Output is correct |
67 |
Correct |
205 ms |
205788 KB |
Output is correct |
68 |
Correct |
201 ms |
205756 KB |
Output is correct |
69 |
Correct |
23 ms |
47316 KB |
Output is correct |
70 |
Correct |
23 ms |
47316 KB |
Output is correct |
71 |
Correct |
24 ms |
47408 KB |
Output is correct |
72 |
Correct |
27 ms |
47280 KB |
Output is correct |
73 |
Correct |
23 ms |
47316 KB |
Output is correct |
74 |
Correct |
25 ms |
47380 KB |
Output is correct |
75 |
Correct |
24 ms |
47400 KB |
Output is correct |
76 |
Correct |
25 ms |
47304 KB |
Output is correct |
77 |
Correct |
26 ms |
47312 KB |
Output is correct |
78 |
Correct |
24 ms |
47300 KB |
Output is correct |
79 |
Correct |
26 ms |
47420 KB |
Output is correct |
80 |
Correct |
23 ms |
47292 KB |
Output is correct |
81 |
Correct |
29 ms |
47284 KB |
Output is correct |
82 |
Correct |
23 ms |
47296 KB |
Output is correct |
83 |
Correct |
24 ms |
47360 KB |
Output is correct |
84 |
Correct |
26 ms |
47316 KB |
Output is correct |
85 |
Correct |
23 ms |
47436 KB |
Output is correct |
86 |
Correct |
23 ms |
47364 KB |
Output is correct |
87 |
Correct |
23 ms |
47444 KB |
Output is correct |
88 |
Correct |
23 ms |
47440 KB |
Output is correct |
89 |
Correct |
23 ms |
47364 KB |
Output is correct |
90 |
Correct |
24 ms |
47316 KB |
Output is correct |
91 |
Correct |
27 ms |
47384 KB |
Output is correct |
92 |
Correct |
22 ms |
47316 KB |
Output is correct |
93 |
Correct |
22 ms |
47312 KB |
Output is correct |
94 |
Correct |
23 ms |
47380 KB |
Output is correct |
95 |
Correct |
28 ms |
47308 KB |
Output is correct |
96 |
Correct |
23 ms |
47280 KB |
Output is correct |
97 |
Correct |
22 ms |
47316 KB |
Output is correct |
98 |
Correct |
23 ms |
47316 KB |
Output is correct |
99 |
Correct |
23 ms |
47268 KB |
Output is correct |
100 |
Correct |
179 ms |
123476 KB |
Output is correct |
101 |
Correct |
163 ms |
123532 KB |
Output is correct |
102 |
Correct |
173 ms |
123508 KB |
Output is correct |
103 |
Correct |
171 ms |
123560 KB |
Output is correct |
104 |
Correct |
178 ms |
123484 KB |
Output is correct |
105 |
Correct |
185 ms |
150952 KB |
Output is correct |
106 |
Correct |
174 ms |
150940 KB |
Output is correct |
107 |
Correct |
183 ms |
150960 KB |
Output is correct |
108 |
Correct |
201 ms |
150940 KB |
Output is correct |
109 |
Correct |
222 ms |
150956 KB |
Output is correct |
110 |
Correct |
164 ms |
123692 KB |
Output is correct |
111 |
Correct |
177 ms |
123472 KB |
Output is correct |
112 |
Correct |
155 ms |
123500 KB |
Output is correct |
113 |
Correct |
169 ms |
123572 KB |
Output is correct |
114 |
Correct |
156 ms |
123648 KB |
Output is correct |
115 |
Correct |
229 ms |
205764 KB |
Output is correct |
116 |
Correct |
219 ms |
205784 KB |
Output is correct |
117 |
Correct |
219 ms |
205700 KB |
Output is correct |
118 |
Correct |
198 ms |
205888 KB |
Output is correct |
119 |
Correct |
199 ms |
205764 KB |
Output is correct |
120 |
Correct |
158 ms |
123544 KB |
Output is correct |
121 |
Correct |
178 ms |
123540 KB |
Output is correct |
122 |
Correct |
167 ms |
123528 KB |
Output is correct |
123 |
Correct |
165 ms |
123552 KB |
Output is correct |
124 |
Correct |
160 ms |
164676 KB |
Output is correct |
125 |
Correct |
164 ms |
164712 KB |
Output is correct |
126 |
Correct |
163 ms |
164636 KB |
Output is correct |
127 |
Correct |
163 ms |
164676 KB |
Output is correct |
128 |
Correct |
86 ms |
87284 KB |
Output is correct |
129 |
Correct |
93 ms |
87212 KB |
Output is correct |
130 |
Correct |
81 ms |
87292 KB |
Output is correct |
131 |
Correct |
23 ms |
47228 KB |
Output is correct |