#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
const int MAX_N = 1000000;
vector<int> ch[2*MAX_N];
vector<int> tp;
vector<int> sz;
//0 = ?, 1 = min 2 = max
string s;
int parse(int anc, int lt, int t){
if(anc != -1){
ch[anc].push_back(t);
}
sz.push_back(0);
if(s[lt] == '?'){
tp.push_back(0);
sz[t] =1;
return lt+1;
}
else{
if(s[lt+1]== 'i'){
tp.push_back(1);
}
else{
tp.push_back(2);
}
}
int mid =parse(t, lt+4, t+1);
int lid = tp.size();
int last= parse(t, mid+1, tp.size());
sz[t] =sz[t+1] + sz[lid];
/*cout<<t<<" ";
for(int i = lt; i<last+1; i++){
cout<<s[i];
}
cout<<endl;*/
return last+1;
}
pii find_inter(int id){
pii res;
if(tp[id] == 0){
res= {0, 0};
}
else{
pii lh = find_inter(ch[id][0]);
int lid = ch[id][0];
pii rh = find_inter(ch[id][1]);
int rid = ch[id][1];
if(tp[id] ==1){
res = {min(lh.first, rh.first), lh.second+rh.second};
}
else{
res = {lh.first+rh.first+1, sz[id]-1-min(sz[lid]-lh.second-1, sz[rid]-rh.second-1)};
}
}
//cout<<id<<" "<<res.first<<" "<<res.second<<endl;
return res;
}
signed main(){
cin.tie(NULL);
ios_base::sync_with_stdio(false);
cin>>s;
int ended_at =parse(-1, 0,0);
pii res =find_inter(0);
cout<<res.second-res.first+1<<endl;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:79:9: warning: unused variable 'ended_at' [-Wunused-variable]
79 | int ended_at =parse(-1, 0,0);
| ^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
47196 KB |
Output is correct |
2 |
Correct |
11 ms |
47196 KB |
Output is correct |
3 |
Correct |
11 ms |
47196 KB |
Output is correct |
4 |
Correct |
12 ms |
47196 KB |
Output is correct |
5 |
Correct |
11 ms |
47196 KB |
Output is correct |
6 |
Correct |
12 ms |
47260 KB |
Output is correct |
7 |
Correct |
13 ms |
47452 KB |
Output is correct |
8 |
Correct |
11 ms |
47196 KB |
Output is correct |
9 |
Correct |
11 ms |
47196 KB |
Output is correct |
10 |
Correct |
11 ms |
47256 KB |
Output is correct |
11 |
Correct |
12 ms |
47196 KB |
Output is correct |
12 |
Correct |
11 ms |
47196 KB |
Output is correct |
13 |
Correct |
11 ms |
47196 KB |
Output is correct |
14 |
Correct |
11 ms |
47424 KB |
Output is correct |
15 |
Correct |
11 ms |
47196 KB |
Output is correct |
16 |
Correct |
11 ms |
47196 KB |
Output is correct |
17 |
Correct |
12 ms |
47196 KB |
Output is correct |
18 |
Correct |
11 ms |
47196 KB |
Output is correct |
19 |
Correct |
11 ms |
47196 KB |
Output is correct |
20 |
Correct |
12 ms |
47196 KB |
Output is correct |
21 |
Correct |
11 ms |
47196 KB |
Output is correct |
22 |
Correct |
11 ms |
47428 KB |
Output is correct |
23 |
Correct |
11 ms |
47196 KB |
Output is correct |
24 |
Correct |
11 ms |
47236 KB |
Output is correct |
25 |
Correct |
11 ms |
47252 KB |
Output is correct |
26 |
Correct |
11 ms |
47448 KB |
Output is correct |
27 |
Correct |
11 ms |
47196 KB |
Output is correct |
28 |
Correct |
11 ms |
47196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
47196 KB |
Output is correct |
2 |
Correct |
11 ms |
47196 KB |
Output is correct |
3 |
Correct |
11 ms |
47196 KB |
Output is correct |
4 |
Correct |
12 ms |
47196 KB |
Output is correct |
5 |
Correct |
11 ms |
47196 KB |
Output is correct |
6 |
Correct |
12 ms |
47260 KB |
Output is correct |
7 |
Correct |
13 ms |
47452 KB |
Output is correct |
8 |
Correct |
11 ms |
47196 KB |
Output is correct |
9 |
Correct |
11 ms |
47196 KB |
Output is correct |
10 |
Correct |
11 ms |
47256 KB |
Output is correct |
11 |
Correct |
12 ms |
47196 KB |
Output is correct |
12 |
Correct |
11 ms |
47196 KB |
Output is correct |
13 |
Correct |
11 ms |
47196 KB |
Output is correct |
14 |
Correct |
11 ms |
47424 KB |
Output is correct |
15 |
Correct |
11 ms |
47196 KB |
Output is correct |
16 |
Correct |
11 ms |
47196 KB |
Output is correct |
17 |
Correct |
12 ms |
47196 KB |
Output is correct |
18 |
Correct |
11 ms |
47196 KB |
Output is correct |
19 |
Correct |
11 ms |
47196 KB |
Output is correct |
20 |
Correct |
12 ms |
47196 KB |
Output is correct |
21 |
Correct |
11 ms |
47196 KB |
Output is correct |
22 |
Correct |
11 ms |
47428 KB |
Output is correct |
23 |
Correct |
11 ms |
47196 KB |
Output is correct |
24 |
Correct |
11 ms |
47236 KB |
Output is correct |
25 |
Correct |
11 ms |
47252 KB |
Output is correct |
26 |
Correct |
11 ms |
47448 KB |
Output is correct |
27 |
Correct |
11 ms |
47196 KB |
Output is correct |
28 |
Correct |
11 ms |
47196 KB |
Output is correct |
29 |
Correct |
11 ms |
47196 KB |
Output is correct |
30 |
Correct |
11 ms |
47196 KB |
Output is correct |
31 |
Correct |
11 ms |
47196 KB |
Output is correct |
32 |
Correct |
12 ms |
47232 KB |
Output is correct |
33 |
Correct |
11 ms |
47196 KB |
Output is correct |
34 |
Correct |
11 ms |
47196 KB |
Output is correct |
35 |
Correct |
11 ms |
47204 KB |
Output is correct |
36 |
Correct |
12 ms |
47196 KB |
Output is correct |
37 |
Correct |
11 ms |
47196 KB |
Output is correct |
38 |
Correct |
11 ms |
47192 KB |
Output is correct |
39 |
Correct |
11 ms |
47196 KB |
Output is correct |
40 |
Correct |
11 ms |
47196 KB |
Output is correct |
41 |
Correct |
11 ms |
47192 KB |
Output is correct |
42 |
Correct |
11 ms |
47196 KB |
Output is correct |
43 |
Correct |
11 ms |
47196 KB |
Output is correct |
44 |
Correct |
11 ms |
47196 KB |
Output is correct |
45 |
Correct |
11 ms |
47192 KB |
Output is correct |
46 |
Correct |
11 ms |
47196 KB |
Output is correct |
47 |
Correct |
12 ms |
47192 KB |
Output is correct |
48 |
Correct |
11 ms |
47196 KB |
Output is correct |
49 |
Correct |
11 ms |
47196 KB |
Output is correct |
50 |
Correct |
12 ms |
47196 KB |
Output is correct |
51 |
Correct |
12 ms |
47192 KB |
Output is correct |
52 |
Correct |
11 ms |
47196 KB |
Output is correct |
53 |
Correct |
12 ms |
47196 KB |
Output is correct |
54 |
Correct |
11 ms |
47196 KB |
Output is correct |
55 |
Correct |
11 ms |
47424 KB |
Output is correct |
56 |
Correct |
11 ms |
47240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
177 ms |
188744 KB |
Output is correct |
2 |
Correct |
173 ms |
186252 KB |
Output is correct |
3 |
Correct |
188 ms |
186476 KB |
Output is correct |
4 |
Correct |
177 ms |
186356 KB |
Output is correct |
5 |
Correct |
183 ms |
187056 KB |
Output is correct |
6 |
Correct |
183 ms |
189356 KB |
Output is correct |
7 |
Correct |
173 ms |
186540 KB |
Output is correct |
8 |
Correct |
170 ms |
186540 KB |
Output is correct |
9 |
Correct |
184 ms |
189108 KB |
Output is correct |
10 |
Correct |
174 ms |
187052 KB |
Output is correct |
11 |
Correct |
173 ms |
188596 KB |
Output is correct |
12 |
Correct |
182 ms |
187052 KB |
Output is correct |
13 |
Correct |
11 ms |
47192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
47196 KB |
Output is correct |
2 |
Correct |
11 ms |
47196 KB |
Output is correct |
3 |
Correct |
11 ms |
47196 KB |
Output is correct |
4 |
Correct |
12 ms |
47196 KB |
Output is correct |
5 |
Correct |
11 ms |
47196 KB |
Output is correct |
6 |
Correct |
12 ms |
47260 KB |
Output is correct |
7 |
Correct |
13 ms |
47452 KB |
Output is correct |
8 |
Correct |
11 ms |
47196 KB |
Output is correct |
9 |
Correct |
11 ms |
47196 KB |
Output is correct |
10 |
Correct |
11 ms |
47256 KB |
Output is correct |
11 |
Correct |
12 ms |
47196 KB |
Output is correct |
12 |
Correct |
11 ms |
47196 KB |
Output is correct |
13 |
Correct |
11 ms |
47196 KB |
Output is correct |
14 |
Correct |
11 ms |
47424 KB |
Output is correct |
15 |
Correct |
11 ms |
47196 KB |
Output is correct |
16 |
Correct |
11 ms |
47196 KB |
Output is correct |
17 |
Correct |
12 ms |
47196 KB |
Output is correct |
18 |
Correct |
11 ms |
47196 KB |
Output is correct |
19 |
Correct |
11 ms |
47196 KB |
Output is correct |
20 |
Correct |
12 ms |
47196 KB |
Output is correct |
21 |
Correct |
11 ms |
47196 KB |
Output is correct |
22 |
Correct |
11 ms |
47428 KB |
Output is correct |
23 |
Correct |
11 ms |
47196 KB |
Output is correct |
24 |
Correct |
11 ms |
47236 KB |
Output is correct |
25 |
Correct |
11 ms |
47252 KB |
Output is correct |
26 |
Correct |
11 ms |
47448 KB |
Output is correct |
27 |
Correct |
11 ms |
47196 KB |
Output is correct |
28 |
Correct |
11 ms |
47196 KB |
Output is correct |
29 |
Correct |
11 ms |
47196 KB |
Output is correct |
30 |
Correct |
11 ms |
47196 KB |
Output is correct |
31 |
Correct |
11 ms |
47196 KB |
Output is correct |
32 |
Correct |
12 ms |
47232 KB |
Output is correct |
33 |
Correct |
11 ms |
47196 KB |
Output is correct |
34 |
Correct |
11 ms |
47196 KB |
Output is correct |
35 |
Correct |
11 ms |
47204 KB |
Output is correct |
36 |
Correct |
12 ms |
47196 KB |
Output is correct |
37 |
Correct |
11 ms |
47196 KB |
Output is correct |
38 |
Correct |
11 ms |
47192 KB |
Output is correct |
39 |
Correct |
11 ms |
47196 KB |
Output is correct |
40 |
Correct |
11 ms |
47196 KB |
Output is correct |
41 |
Correct |
11 ms |
47192 KB |
Output is correct |
42 |
Correct |
11 ms |
47196 KB |
Output is correct |
43 |
Correct |
11 ms |
47196 KB |
Output is correct |
44 |
Correct |
11 ms |
47196 KB |
Output is correct |
45 |
Correct |
11 ms |
47192 KB |
Output is correct |
46 |
Correct |
11 ms |
47196 KB |
Output is correct |
47 |
Correct |
12 ms |
47192 KB |
Output is correct |
48 |
Correct |
11 ms |
47196 KB |
Output is correct |
49 |
Correct |
11 ms |
47196 KB |
Output is correct |
50 |
Correct |
12 ms |
47196 KB |
Output is correct |
51 |
Correct |
12 ms |
47192 KB |
Output is correct |
52 |
Correct |
11 ms |
47196 KB |
Output is correct |
53 |
Correct |
12 ms |
47196 KB |
Output is correct |
54 |
Correct |
11 ms |
47196 KB |
Output is correct |
55 |
Correct |
11 ms |
47424 KB |
Output is correct |
56 |
Correct |
11 ms |
47240 KB |
Output is correct |
57 |
Correct |
12 ms |
47480 KB |
Output is correct |
58 |
Correct |
11 ms |
47448 KB |
Output is correct |
59 |
Correct |
11 ms |
47480 KB |
Output is correct |
60 |
Correct |
11 ms |
47392 KB |
Output is correct |
61 |
Correct |
11 ms |
47448 KB |
Output is correct |
62 |
Correct |
11 ms |
47452 KB |
Output is correct |
63 |
Correct |
12 ms |
47424 KB |
Output is correct |
64 |
Correct |
13 ms |
47452 KB |
Output is correct |
65 |
Correct |
11 ms |
47492 KB |
Output is correct |
66 |
Correct |
11 ms |
47452 KB |
Output is correct |
67 |
Correct |
11 ms |
47452 KB |
Output is correct |
68 |
Correct |
12 ms |
47452 KB |
Output is correct |
69 |
Correct |
11 ms |
47452 KB |
Output is correct |
70 |
Correct |
11 ms |
47452 KB |
Output is correct |
71 |
Correct |
11 ms |
47264 KB |
Output is correct |
72 |
Correct |
11 ms |
47452 KB |
Output is correct |
73 |
Correct |
11 ms |
47448 KB |
Output is correct |
74 |
Correct |
11 ms |
47452 KB |
Output is correct |
75 |
Correct |
12 ms |
47452 KB |
Output is correct |
76 |
Correct |
11 ms |
47452 KB |
Output is correct |
77 |
Correct |
11 ms |
47280 KB |
Output is correct |
78 |
Correct |
11 ms |
47452 KB |
Output is correct |
79 |
Correct |
12 ms |
47448 KB |
Output is correct |
80 |
Correct |
12 ms |
47452 KB |
Output is correct |
81 |
Correct |
11 ms |
47452 KB |
Output is correct |
82 |
Correct |
11 ms |
47448 KB |
Output is correct |
83 |
Correct |
12 ms |
47452 KB |
Output is correct |
84 |
Correct |
11 ms |
47452 KB |
Output is correct |
85 |
Correct |
13 ms |
47452 KB |
Output is correct |
86 |
Correct |
11 ms |
47196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
47196 KB |
Output is correct |
2 |
Correct |
11 ms |
47196 KB |
Output is correct |
3 |
Correct |
11 ms |
47196 KB |
Output is correct |
4 |
Correct |
12 ms |
47196 KB |
Output is correct |
5 |
Correct |
11 ms |
47196 KB |
Output is correct |
6 |
Correct |
12 ms |
47260 KB |
Output is correct |
7 |
Correct |
13 ms |
47452 KB |
Output is correct |
8 |
Correct |
11 ms |
47196 KB |
Output is correct |
9 |
Correct |
11 ms |
47196 KB |
Output is correct |
10 |
Correct |
11 ms |
47256 KB |
Output is correct |
11 |
Correct |
12 ms |
47196 KB |
Output is correct |
12 |
Correct |
11 ms |
47196 KB |
Output is correct |
13 |
Correct |
11 ms |
47196 KB |
Output is correct |
14 |
Correct |
11 ms |
47424 KB |
Output is correct |
15 |
Correct |
11 ms |
47196 KB |
Output is correct |
16 |
Correct |
11 ms |
47196 KB |
Output is correct |
17 |
Correct |
12 ms |
47196 KB |
Output is correct |
18 |
Correct |
11 ms |
47196 KB |
Output is correct |
19 |
Correct |
11 ms |
47196 KB |
Output is correct |
20 |
Correct |
12 ms |
47196 KB |
Output is correct |
21 |
Correct |
11 ms |
47196 KB |
Output is correct |
22 |
Correct |
11 ms |
47428 KB |
Output is correct |
23 |
Correct |
11 ms |
47196 KB |
Output is correct |
24 |
Correct |
11 ms |
47236 KB |
Output is correct |
25 |
Correct |
11 ms |
47252 KB |
Output is correct |
26 |
Correct |
11 ms |
47448 KB |
Output is correct |
27 |
Correct |
11 ms |
47196 KB |
Output is correct |
28 |
Correct |
11 ms |
47196 KB |
Output is correct |
29 |
Correct |
11 ms |
47196 KB |
Output is correct |
30 |
Correct |
11 ms |
47196 KB |
Output is correct |
31 |
Correct |
11 ms |
47196 KB |
Output is correct |
32 |
Correct |
12 ms |
47232 KB |
Output is correct |
33 |
Correct |
11 ms |
47196 KB |
Output is correct |
34 |
Correct |
11 ms |
47196 KB |
Output is correct |
35 |
Correct |
11 ms |
47204 KB |
Output is correct |
36 |
Correct |
12 ms |
47196 KB |
Output is correct |
37 |
Correct |
11 ms |
47196 KB |
Output is correct |
38 |
Correct |
11 ms |
47192 KB |
Output is correct |
39 |
Correct |
11 ms |
47196 KB |
Output is correct |
40 |
Correct |
11 ms |
47196 KB |
Output is correct |
41 |
Correct |
11 ms |
47192 KB |
Output is correct |
42 |
Correct |
11 ms |
47196 KB |
Output is correct |
43 |
Correct |
11 ms |
47196 KB |
Output is correct |
44 |
Correct |
11 ms |
47196 KB |
Output is correct |
45 |
Correct |
11 ms |
47192 KB |
Output is correct |
46 |
Correct |
11 ms |
47196 KB |
Output is correct |
47 |
Correct |
12 ms |
47192 KB |
Output is correct |
48 |
Correct |
11 ms |
47196 KB |
Output is correct |
49 |
Correct |
11 ms |
47196 KB |
Output is correct |
50 |
Correct |
12 ms |
47196 KB |
Output is correct |
51 |
Correct |
12 ms |
47192 KB |
Output is correct |
52 |
Correct |
11 ms |
47196 KB |
Output is correct |
53 |
Correct |
12 ms |
47196 KB |
Output is correct |
54 |
Correct |
11 ms |
47196 KB |
Output is correct |
55 |
Correct |
11 ms |
47424 KB |
Output is correct |
56 |
Correct |
11 ms |
47240 KB |
Output is correct |
57 |
Correct |
177 ms |
188744 KB |
Output is correct |
58 |
Correct |
173 ms |
186252 KB |
Output is correct |
59 |
Correct |
188 ms |
186476 KB |
Output is correct |
60 |
Correct |
177 ms |
186356 KB |
Output is correct |
61 |
Correct |
183 ms |
187056 KB |
Output is correct |
62 |
Correct |
183 ms |
189356 KB |
Output is correct |
63 |
Correct |
173 ms |
186540 KB |
Output is correct |
64 |
Correct |
170 ms |
186540 KB |
Output is correct |
65 |
Correct |
184 ms |
189108 KB |
Output is correct |
66 |
Correct |
174 ms |
187052 KB |
Output is correct |
67 |
Correct |
173 ms |
188596 KB |
Output is correct |
68 |
Correct |
182 ms |
187052 KB |
Output is correct |
69 |
Correct |
11 ms |
47192 KB |
Output is correct |
70 |
Correct |
12 ms |
47480 KB |
Output is correct |
71 |
Correct |
11 ms |
47448 KB |
Output is correct |
72 |
Correct |
11 ms |
47480 KB |
Output is correct |
73 |
Correct |
11 ms |
47392 KB |
Output is correct |
74 |
Correct |
11 ms |
47448 KB |
Output is correct |
75 |
Correct |
11 ms |
47452 KB |
Output is correct |
76 |
Correct |
12 ms |
47424 KB |
Output is correct |
77 |
Correct |
13 ms |
47452 KB |
Output is correct |
78 |
Correct |
11 ms |
47492 KB |
Output is correct |
79 |
Correct |
11 ms |
47452 KB |
Output is correct |
80 |
Correct |
11 ms |
47452 KB |
Output is correct |
81 |
Correct |
12 ms |
47452 KB |
Output is correct |
82 |
Correct |
11 ms |
47452 KB |
Output is correct |
83 |
Correct |
11 ms |
47452 KB |
Output is correct |
84 |
Correct |
11 ms |
47264 KB |
Output is correct |
85 |
Correct |
11 ms |
47452 KB |
Output is correct |
86 |
Correct |
11 ms |
47448 KB |
Output is correct |
87 |
Correct |
11 ms |
47452 KB |
Output is correct |
88 |
Correct |
12 ms |
47452 KB |
Output is correct |
89 |
Correct |
11 ms |
47452 KB |
Output is correct |
90 |
Correct |
11 ms |
47280 KB |
Output is correct |
91 |
Correct |
11 ms |
47452 KB |
Output is correct |
92 |
Correct |
12 ms |
47448 KB |
Output is correct |
93 |
Correct |
12 ms |
47452 KB |
Output is correct |
94 |
Correct |
11 ms |
47452 KB |
Output is correct |
95 |
Correct |
11 ms |
47448 KB |
Output is correct |
96 |
Correct |
12 ms |
47452 KB |
Output is correct |
97 |
Correct |
11 ms |
47452 KB |
Output is correct |
98 |
Correct |
13 ms |
47452 KB |
Output is correct |
99 |
Correct |
11 ms |
47196 KB |
Output is correct |
100 |
Correct |
129 ms |
123744 KB |
Output is correct |
101 |
Correct |
129 ms |
123520 KB |
Output is correct |
102 |
Correct |
120 ms |
124540 KB |
Output is correct |
103 |
Correct |
127 ms |
125616 KB |
Output is correct |
104 |
Correct |
121 ms |
124572 KB |
Output is correct |
105 |
Correct |
152 ms |
144360 KB |
Output is correct |
106 |
Correct |
153 ms |
144756 KB |
Output is correct |
107 |
Correct |
146 ms |
145932 KB |
Output is correct |
108 |
Correct |
150 ms |
146792 KB |
Output is correct |
109 |
Correct |
151 ms |
144432 KB |
Output is correct |
110 |
Correct |
132 ms |
124080 KB |
Output is correct |
111 |
Correct |
132 ms |
123504 KB |
Output is correct |
112 |
Correct |
129 ms |
123648 KB |
Output is correct |
113 |
Correct |
131 ms |
124796 KB |
Output is correct |
114 |
Correct |
131 ms |
123680 KB |
Output is correct |
115 |
Correct |
203 ms |
186492 KB |
Output is correct |
116 |
Correct |
191 ms |
186608 KB |
Output is correct |
117 |
Correct |
174 ms |
186800 KB |
Output is correct |
118 |
Correct |
180 ms |
186712 KB |
Output is correct |
119 |
Correct |
193 ms |
187308 KB |
Output is correct |
120 |
Correct |
124 ms |
123536 KB |
Output is correct |
121 |
Correct |
124 ms |
125100 KB |
Output is correct |
122 |
Correct |
145 ms |
124820 KB |
Output is correct |
123 |
Correct |
135 ms |
123784 KB |
Output is correct |
124 |
Correct |
139 ms |
155312 KB |
Output is correct |
125 |
Correct |
144 ms |
155144 KB |
Output is correct |
126 |
Correct |
149 ms |
157428 KB |
Output is correct |
127 |
Correct |
143 ms |
155452 KB |
Output is correct |
128 |
Correct |
68 ms |
87432 KB |
Output is correct |
129 |
Correct |
66 ms |
87372 KB |
Output is correct |
130 |
Correct |
69 ms |
87248 KB |
Output is correct |
131 |
Correct |
11 ms |
47192 KB |
Output is correct |