#include <iostream>
#include <vector>
using namespace std;
const int stala=3e6+10;
vector<int>w[stala];
int dp[stala][2];
int tab[stala]; //0-? 1-min 2-max
int index=0,l=0;
string s;
void make_edge(int x,int y)
{
if(x==-1||y==-1){
return;
}
w[x].push_back(y);
w[y].push_back(x);
}
int f(int pop,int start)
{
index++;
make_edge(pop,index);
int current_index=index;
if(s[start]=='?'){
l++;
return start;
}
else if(s[start+1]=='i'){
tab[current_index]=1;
int pom=f(current_index,start+4)+2;
return f(current_index,pom)+1;
}
else{
tab[current_index]=2;
int pom=f(current_index,start+4)+2;
return f(current_index,pom)+1;
}
}
void dfs(int k)
{
if(tab[k]==0){
dp[k][0]=1;
dp[k][1]=1;
}
else if(k==1){
dfs(w[k][0]);
dfs(w[k][1]);
int a1=dp[w[k][0]][0];
int b1=dp[w[k][1]][0];
int a2=dp[w[k][0]][1];
int b2=dp[w[k][1]][1];
if(tab[k]==1){
dp[k][0]=min(a1,b1);
dp[k][1]=a2+b2;
}
else{
dp[k][0]=a1+b1;
dp[k][1]=min(a2,b2);
}
}
else{
dfs(w[k][1]);
dfs(w[k][2]);
int a1=dp[w[k][1]][0];
int b1=dp[w[k][2]][0];
int a2=dp[w[k][1]][1];
int b2=dp[w[k][2]][1];
if(tab[k]==1){
dp[k][0]=min(a1,b1);
dp[k][1]=a2+b2;
}
else{
dp[k][0]=a1+b1;
dp[k][1]=min(a2,b2);
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>s;
f(-1,0);
dfs(1);
int x=dp[1][0];
int y=l-dp[1][1]+1;
cout<<max(0,y-x+1);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
73048 KB |
Output is correct |
2 |
Correct |
16 ms |
73052 KB |
Output is correct |
3 |
Correct |
15 ms |
73048 KB |
Output is correct |
4 |
Correct |
15 ms |
73048 KB |
Output is correct |
5 |
Correct |
16 ms |
73048 KB |
Output is correct |
6 |
Correct |
15 ms |
73048 KB |
Output is correct |
7 |
Correct |
15 ms |
73048 KB |
Output is correct |
8 |
Correct |
15 ms |
73048 KB |
Output is correct |
9 |
Correct |
15 ms |
73048 KB |
Output is correct |
10 |
Correct |
15 ms |
73048 KB |
Output is correct |
11 |
Correct |
15 ms |
73048 KB |
Output is correct |
12 |
Correct |
16 ms |
73052 KB |
Output is correct |
13 |
Correct |
15 ms |
73048 KB |
Output is correct |
14 |
Correct |
16 ms |
73048 KB |
Output is correct |
15 |
Correct |
18 ms |
73048 KB |
Output is correct |
16 |
Correct |
15 ms |
73048 KB |
Output is correct |
17 |
Correct |
15 ms |
73048 KB |
Output is correct |
18 |
Correct |
16 ms |
73304 KB |
Output is correct |
19 |
Correct |
16 ms |
73048 KB |
Output is correct |
20 |
Correct |
15 ms |
73048 KB |
Output is correct |
21 |
Correct |
16 ms |
73560 KB |
Output is correct |
22 |
Correct |
16 ms |
73048 KB |
Output is correct |
23 |
Correct |
15 ms |
73052 KB |
Output is correct |
24 |
Correct |
15 ms |
73052 KB |
Output is correct |
25 |
Correct |
15 ms |
73048 KB |
Output is correct |
26 |
Correct |
15 ms |
73124 KB |
Output is correct |
27 |
Correct |
16 ms |
73052 KB |
Output is correct |
28 |
Correct |
15 ms |
73048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
73048 KB |
Output is correct |
2 |
Correct |
16 ms |
73052 KB |
Output is correct |
3 |
Correct |
15 ms |
73048 KB |
Output is correct |
4 |
Correct |
15 ms |
73048 KB |
Output is correct |
5 |
Correct |
16 ms |
73048 KB |
Output is correct |
6 |
Correct |
15 ms |
73048 KB |
Output is correct |
7 |
Correct |
15 ms |
73048 KB |
Output is correct |
8 |
Correct |
15 ms |
73048 KB |
Output is correct |
9 |
Correct |
15 ms |
73048 KB |
Output is correct |
10 |
Correct |
15 ms |
73048 KB |
Output is correct |
11 |
Correct |
15 ms |
73048 KB |
Output is correct |
12 |
Correct |
16 ms |
73052 KB |
Output is correct |
13 |
Correct |
15 ms |
73048 KB |
Output is correct |
14 |
Correct |
16 ms |
73048 KB |
Output is correct |
15 |
Correct |
18 ms |
73048 KB |
Output is correct |
16 |
Correct |
15 ms |
73048 KB |
Output is correct |
17 |
Correct |
15 ms |
73048 KB |
Output is correct |
18 |
Correct |
16 ms |
73304 KB |
Output is correct |
19 |
Correct |
16 ms |
73048 KB |
Output is correct |
20 |
Correct |
15 ms |
73048 KB |
Output is correct |
21 |
Correct |
16 ms |
73560 KB |
Output is correct |
22 |
Correct |
16 ms |
73048 KB |
Output is correct |
23 |
Correct |
15 ms |
73052 KB |
Output is correct |
24 |
Correct |
15 ms |
73052 KB |
Output is correct |
25 |
Correct |
15 ms |
73048 KB |
Output is correct |
26 |
Correct |
15 ms |
73124 KB |
Output is correct |
27 |
Correct |
16 ms |
73052 KB |
Output is correct |
28 |
Correct |
15 ms |
73048 KB |
Output is correct |
29 |
Correct |
15 ms |
73048 KB |
Output is correct |
30 |
Correct |
15 ms |
73048 KB |
Output is correct |
31 |
Correct |
15 ms |
73048 KB |
Output is correct |
32 |
Correct |
15 ms |
73048 KB |
Output is correct |
33 |
Correct |
16 ms |
73048 KB |
Output is correct |
34 |
Correct |
15 ms |
73048 KB |
Output is correct |
35 |
Correct |
15 ms |
73048 KB |
Output is correct |
36 |
Correct |
16 ms |
73304 KB |
Output is correct |
37 |
Correct |
15 ms |
72968 KB |
Output is correct |
38 |
Correct |
15 ms |
73048 KB |
Output is correct |
39 |
Correct |
15 ms |
73120 KB |
Output is correct |
40 |
Correct |
16 ms |
73304 KB |
Output is correct |
41 |
Correct |
15 ms |
73048 KB |
Output is correct |
42 |
Correct |
15 ms |
72988 KB |
Output is correct |
43 |
Correct |
15 ms |
73048 KB |
Output is correct |
44 |
Correct |
15 ms |
73048 KB |
Output is correct |
45 |
Correct |
15 ms |
73048 KB |
Output is correct |
46 |
Correct |
15 ms |
73304 KB |
Output is correct |
47 |
Correct |
15 ms |
73120 KB |
Output is correct |
48 |
Correct |
15 ms |
73052 KB |
Output is correct |
49 |
Correct |
16 ms |
73048 KB |
Output is correct |
50 |
Correct |
15 ms |
73048 KB |
Output is correct |
51 |
Correct |
15 ms |
73048 KB |
Output is correct |
52 |
Correct |
15 ms |
73048 KB |
Output is correct |
53 |
Correct |
15 ms |
73048 KB |
Output is correct |
54 |
Correct |
15 ms |
73048 KB |
Output is correct |
55 |
Correct |
15 ms |
73048 KB |
Output is correct |
56 |
Correct |
15 ms |
73052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
268 ms |
219852 KB |
Output is correct |
2 |
Correct |
238 ms |
219344 KB |
Output is correct |
3 |
Correct |
249 ms |
219160 KB |
Output is correct |
4 |
Correct |
241 ms |
219084 KB |
Output is correct |
5 |
Correct |
249 ms |
220072 KB |
Output is correct |
6 |
Correct |
235 ms |
219720 KB |
Output is correct |
7 |
Correct |
257 ms |
220364 KB |
Output is correct |
8 |
Correct |
235 ms |
219084 KB |
Output is correct |
9 |
Correct |
255 ms |
219436 KB |
Output is correct |
10 |
Correct |
236 ms |
220108 KB |
Output is correct |
11 |
Correct |
246 ms |
219084 KB |
Output is correct |
12 |
Correct |
254 ms |
220364 KB |
Output is correct |
13 |
Correct |
15 ms |
73048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
73048 KB |
Output is correct |
2 |
Correct |
16 ms |
73052 KB |
Output is correct |
3 |
Correct |
15 ms |
73048 KB |
Output is correct |
4 |
Correct |
15 ms |
73048 KB |
Output is correct |
5 |
Correct |
16 ms |
73048 KB |
Output is correct |
6 |
Correct |
15 ms |
73048 KB |
Output is correct |
7 |
Correct |
15 ms |
73048 KB |
Output is correct |
8 |
Correct |
15 ms |
73048 KB |
Output is correct |
9 |
Correct |
15 ms |
73048 KB |
Output is correct |
10 |
Correct |
15 ms |
73048 KB |
Output is correct |
11 |
Correct |
15 ms |
73048 KB |
Output is correct |
12 |
Correct |
16 ms |
73052 KB |
Output is correct |
13 |
Correct |
15 ms |
73048 KB |
Output is correct |
14 |
Correct |
16 ms |
73048 KB |
Output is correct |
15 |
Correct |
18 ms |
73048 KB |
Output is correct |
16 |
Correct |
15 ms |
73048 KB |
Output is correct |
17 |
Correct |
15 ms |
73048 KB |
Output is correct |
18 |
Correct |
16 ms |
73304 KB |
Output is correct |
19 |
Correct |
16 ms |
73048 KB |
Output is correct |
20 |
Correct |
15 ms |
73048 KB |
Output is correct |
21 |
Correct |
16 ms |
73560 KB |
Output is correct |
22 |
Correct |
16 ms |
73048 KB |
Output is correct |
23 |
Correct |
15 ms |
73052 KB |
Output is correct |
24 |
Correct |
15 ms |
73052 KB |
Output is correct |
25 |
Correct |
15 ms |
73048 KB |
Output is correct |
26 |
Correct |
15 ms |
73124 KB |
Output is correct |
27 |
Correct |
16 ms |
73052 KB |
Output is correct |
28 |
Correct |
15 ms |
73048 KB |
Output is correct |
29 |
Correct |
15 ms |
73048 KB |
Output is correct |
30 |
Correct |
15 ms |
73048 KB |
Output is correct |
31 |
Correct |
15 ms |
73048 KB |
Output is correct |
32 |
Correct |
15 ms |
73048 KB |
Output is correct |
33 |
Correct |
16 ms |
73048 KB |
Output is correct |
34 |
Correct |
15 ms |
73048 KB |
Output is correct |
35 |
Correct |
15 ms |
73048 KB |
Output is correct |
36 |
Correct |
16 ms |
73304 KB |
Output is correct |
37 |
Correct |
15 ms |
72968 KB |
Output is correct |
38 |
Correct |
15 ms |
73048 KB |
Output is correct |
39 |
Correct |
15 ms |
73120 KB |
Output is correct |
40 |
Correct |
16 ms |
73304 KB |
Output is correct |
41 |
Correct |
15 ms |
73048 KB |
Output is correct |
42 |
Correct |
15 ms |
72988 KB |
Output is correct |
43 |
Correct |
15 ms |
73048 KB |
Output is correct |
44 |
Correct |
15 ms |
73048 KB |
Output is correct |
45 |
Correct |
15 ms |
73048 KB |
Output is correct |
46 |
Correct |
15 ms |
73304 KB |
Output is correct |
47 |
Correct |
15 ms |
73120 KB |
Output is correct |
48 |
Correct |
15 ms |
73052 KB |
Output is correct |
49 |
Correct |
16 ms |
73048 KB |
Output is correct |
50 |
Correct |
15 ms |
73048 KB |
Output is correct |
51 |
Correct |
15 ms |
73048 KB |
Output is correct |
52 |
Correct |
15 ms |
73048 KB |
Output is correct |
53 |
Correct |
15 ms |
73048 KB |
Output is correct |
54 |
Correct |
15 ms |
73048 KB |
Output is correct |
55 |
Correct |
15 ms |
73048 KB |
Output is correct |
56 |
Correct |
15 ms |
73052 KB |
Output is correct |
57 |
Correct |
16 ms |
73052 KB |
Output is correct |
58 |
Correct |
15 ms |
73048 KB |
Output is correct |
59 |
Correct |
15 ms |
73052 KB |
Output is correct |
60 |
Correct |
15 ms |
73048 KB |
Output is correct |
61 |
Correct |
15 ms |
73048 KB |
Output is correct |
62 |
Correct |
15 ms |
73048 KB |
Output is correct |
63 |
Correct |
17 ms |
73304 KB |
Output is correct |
64 |
Correct |
16 ms |
73124 KB |
Output is correct |
65 |
Correct |
16 ms |
73048 KB |
Output is correct |
66 |
Correct |
15 ms |
73048 KB |
Output is correct |
67 |
Correct |
15 ms |
73212 KB |
Output is correct |
68 |
Correct |
16 ms |
73048 KB |
Output is correct |
69 |
Correct |
17 ms |
73000 KB |
Output is correct |
70 |
Correct |
15 ms |
73048 KB |
Output is correct |
71 |
Correct |
15 ms |
73048 KB |
Output is correct |
72 |
Correct |
15 ms |
73048 KB |
Output is correct |
73 |
Correct |
16 ms |
73048 KB |
Output is correct |
74 |
Correct |
15 ms |
73048 KB |
Output is correct |
75 |
Correct |
15 ms |
73052 KB |
Output is correct |
76 |
Correct |
15 ms |
73048 KB |
Output is correct |
77 |
Correct |
16 ms |
73048 KB |
Output is correct |
78 |
Correct |
17 ms |
73304 KB |
Output is correct |
79 |
Correct |
15 ms |
73048 KB |
Output is correct |
80 |
Correct |
15 ms |
73048 KB |
Output is correct |
81 |
Correct |
15 ms |
73052 KB |
Output is correct |
82 |
Correct |
15 ms |
73048 KB |
Output is correct |
83 |
Correct |
16 ms |
73048 KB |
Output is correct |
84 |
Correct |
17 ms |
72956 KB |
Output is correct |
85 |
Correct |
15 ms |
73048 KB |
Output is correct |
86 |
Correct |
16 ms |
72972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
73048 KB |
Output is correct |
2 |
Correct |
16 ms |
73052 KB |
Output is correct |
3 |
Correct |
15 ms |
73048 KB |
Output is correct |
4 |
Correct |
15 ms |
73048 KB |
Output is correct |
5 |
Correct |
16 ms |
73048 KB |
Output is correct |
6 |
Correct |
15 ms |
73048 KB |
Output is correct |
7 |
Correct |
15 ms |
73048 KB |
Output is correct |
8 |
Correct |
15 ms |
73048 KB |
Output is correct |
9 |
Correct |
15 ms |
73048 KB |
Output is correct |
10 |
Correct |
15 ms |
73048 KB |
Output is correct |
11 |
Correct |
15 ms |
73048 KB |
Output is correct |
12 |
Correct |
16 ms |
73052 KB |
Output is correct |
13 |
Correct |
15 ms |
73048 KB |
Output is correct |
14 |
Correct |
16 ms |
73048 KB |
Output is correct |
15 |
Correct |
18 ms |
73048 KB |
Output is correct |
16 |
Correct |
15 ms |
73048 KB |
Output is correct |
17 |
Correct |
15 ms |
73048 KB |
Output is correct |
18 |
Correct |
16 ms |
73304 KB |
Output is correct |
19 |
Correct |
16 ms |
73048 KB |
Output is correct |
20 |
Correct |
15 ms |
73048 KB |
Output is correct |
21 |
Correct |
16 ms |
73560 KB |
Output is correct |
22 |
Correct |
16 ms |
73048 KB |
Output is correct |
23 |
Correct |
15 ms |
73052 KB |
Output is correct |
24 |
Correct |
15 ms |
73052 KB |
Output is correct |
25 |
Correct |
15 ms |
73048 KB |
Output is correct |
26 |
Correct |
15 ms |
73124 KB |
Output is correct |
27 |
Correct |
16 ms |
73052 KB |
Output is correct |
28 |
Correct |
15 ms |
73048 KB |
Output is correct |
29 |
Correct |
15 ms |
73048 KB |
Output is correct |
30 |
Correct |
15 ms |
73048 KB |
Output is correct |
31 |
Correct |
15 ms |
73048 KB |
Output is correct |
32 |
Correct |
15 ms |
73048 KB |
Output is correct |
33 |
Correct |
16 ms |
73048 KB |
Output is correct |
34 |
Correct |
15 ms |
73048 KB |
Output is correct |
35 |
Correct |
15 ms |
73048 KB |
Output is correct |
36 |
Correct |
16 ms |
73304 KB |
Output is correct |
37 |
Correct |
15 ms |
72968 KB |
Output is correct |
38 |
Correct |
15 ms |
73048 KB |
Output is correct |
39 |
Correct |
15 ms |
73120 KB |
Output is correct |
40 |
Correct |
16 ms |
73304 KB |
Output is correct |
41 |
Correct |
15 ms |
73048 KB |
Output is correct |
42 |
Correct |
15 ms |
72988 KB |
Output is correct |
43 |
Correct |
15 ms |
73048 KB |
Output is correct |
44 |
Correct |
15 ms |
73048 KB |
Output is correct |
45 |
Correct |
15 ms |
73048 KB |
Output is correct |
46 |
Correct |
15 ms |
73304 KB |
Output is correct |
47 |
Correct |
15 ms |
73120 KB |
Output is correct |
48 |
Correct |
15 ms |
73052 KB |
Output is correct |
49 |
Correct |
16 ms |
73048 KB |
Output is correct |
50 |
Correct |
15 ms |
73048 KB |
Output is correct |
51 |
Correct |
15 ms |
73048 KB |
Output is correct |
52 |
Correct |
15 ms |
73048 KB |
Output is correct |
53 |
Correct |
15 ms |
73048 KB |
Output is correct |
54 |
Correct |
15 ms |
73048 KB |
Output is correct |
55 |
Correct |
15 ms |
73048 KB |
Output is correct |
56 |
Correct |
15 ms |
73052 KB |
Output is correct |
57 |
Correct |
268 ms |
219852 KB |
Output is correct |
58 |
Correct |
238 ms |
219344 KB |
Output is correct |
59 |
Correct |
249 ms |
219160 KB |
Output is correct |
60 |
Correct |
241 ms |
219084 KB |
Output is correct |
61 |
Correct |
249 ms |
220072 KB |
Output is correct |
62 |
Correct |
235 ms |
219720 KB |
Output is correct |
63 |
Correct |
257 ms |
220364 KB |
Output is correct |
64 |
Correct |
235 ms |
219084 KB |
Output is correct |
65 |
Correct |
255 ms |
219436 KB |
Output is correct |
66 |
Correct |
236 ms |
220108 KB |
Output is correct |
67 |
Correct |
246 ms |
219084 KB |
Output is correct |
68 |
Correct |
254 ms |
220364 KB |
Output is correct |
69 |
Correct |
15 ms |
73048 KB |
Output is correct |
70 |
Correct |
16 ms |
73052 KB |
Output is correct |
71 |
Correct |
15 ms |
73048 KB |
Output is correct |
72 |
Correct |
15 ms |
73052 KB |
Output is correct |
73 |
Correct |
15 ms |
73048 KB |
Output is correct |
74 |
Correct |
15 ms |
73048 KB |
Output is correct |
75 |
Correct |
15 ms |
73048 KB |
Output is correct |
76 |
Correct |
17 ms |
73304 KB |
Output is correct |
77 |
Correct |
16 ms |
73124 KB |
Output is correct |
78 |
Correct |
16 ms |
73048 KB |
Output is correct |
79 |
Correct |
15 ms |
73048 KB |
Output is correct |
80 |
Correct |
15 ms |
73212 KB |
Output is correct |
81 |
Correct |
16 ms |
73048 KB |
Output is correct |
82 |
Correct |
17 ms |
73000 KB |
Output is correct |
83 |
Correct |
15 ms |
73048 KB |
Output is correct |
84 |
Correct |
15 ms |
73048 KB |
Output is correct |
85 |
Correct |
15 ms |
73048 KB |
Output is correct |
86 |
Correct |
16 ms |
73048 KB |
Output is correct |
87 |
Correct |
15 ms |
73048 KB |
Output is correct |
88 |
Correct |
15 ms |
73052 KB |
Output is correct |
89 |
Correct |
15 ms |
73048 KB |
Output is correct |
90 |
Correct |
16 ms |
73048 KB |
Output is correct |
91 |
Correct |
17 ms |
73304 KB |
Output is correct |
92 |
Correct |
15 ms |
73048 KB |
Output is correct |
93 |
Correct |
15 ms |
73048 KB |
Output is correct |
94 |
Correct |
15 ms |
73052 KB |
Output is correct |
95 |
Correct |
15 ms |
73048 KB |
Output is correct |
96 |
Correct |
16 ms |
73048 KB |
Output is correct |
97 |
Correct |
17 ms |
72956 KB |
Output is correct |
98 |
Correct |
15 ms |
73048 KB |
Output is correct |
99 |
Correct |
16 ms |
72972 KB |
Output is correct |
100 |
Correct |
215 ms |
174216 KB |
Output is correct |
101 |
Correct |
214 ms |
174028 KB |
Output is correct |
102 |
Correct |
208 ms |
175048 KB |
Output is correct |
103 |
Correct |
205 ms |
174028 KB |
Output is correct |
104 |
Correct |
203 ms |
174540 KB |
Output is correct |
105 |
Correct |
242 ms |
191208 KB |
Output is correct |
106 |
Correct |
235 ms |
189740 KB |
Output is correct |
107 |
Correct |
240 ms |
190152 KB |
Output is correct |
108 |
Correct |
234 ms |
190016 KB |
Output is correct |
109 |
Correct |
257 ms |
190572 KB |
Output is correct |
110 |
Correct |
215 ms |
174220 KB |
Output is correct |
111 |
Correct |
218 ms |
174784 KB |
Output is correct |
112 |
Correct |
223 ms |
175056 KB |
Output is correct |
113 |
Correct |
233 ms |
174240 KB |
Output is correct |
114 |
Correct |
223 ms |
174988 KB |
Output is correct |
115 |
Correct |
370 ms |
219600 KB |
Output is correct |
116 |
Correct |
240 ms |
219224 KB |
Output is correct |
117 |
Correct |
244 ms |
219176 KB |
Output is correct |
118 |
Correct |
241 ms |
219084 KB |
Output is correct |
119 |
Correct |
246 ms |
220388 KB |
Output is correct |
120 |
Correct |
216 ms |
174332 KB |
Output is correct |
121 |
Correct |
216 ms |
175048 KB |
Output is correct |
122 |
Correct |
217 ms |
174896 KB |
Output is correct |
123 |
Correct |
225 ms |
174996 KB |
Output is correct |
124 |
Correct |
257 ms |
198864 KB |
Output is correct |
125 |
Correct |
224 ms |
198964 KB |
Output is correct |
126 |
Correct |
221 ms |
198348 KB |
Output is correct |
127 |
Correct |
225 ms |
198028 KB |
Output is correct |
128 |
Correct |
121 ms |
125392 KB |
Output is correct |
129 |
Correct |
117 ms |
125692 KB |
Output is correct |
130 |
Correct |
112 ms |
125392 KB |
Output is correct |
131 |
Correct |
15 ms |
73048 KB |
Output is correct |