#include <bits/stdc++.h>
#define MAX 105005
typedef std::pair<int,int> pii;
///Garantido que con=2
std::vector<int> con[MAX];
int types[MAX];
enum tipos {MINIMO=1,MAXIMO};
int N;
int rodada=42;
///0 -> Menor que objetivo
///1 -> Maior que objetivo
int turno[MAX][2];
int tab[MAX][2];
int dp(int pos,int modo){
if(!types[pos]){///Folha
return 1;
}
if(turno[pos][modo]==rodada)return tab[pos][modo];
turno[pos][modo]=rodada;
int ans=1e9;
///Procurando valores menores que objetivo
if(modo==0){
if(types[pos]==MINIMO){
ans=std::min(ans,dp(con[pos][0],modo));
ans=std::min(ans,dp(con[pos][1],modo));
}else {
ans=dp(con[pos][0],modo)+dp(con[pos][1],modo);
}
///Procurando valores maiores que objetivo
}else {
if(types[pos]==MINIMO){
ans=dp(con[pos][0],modo)+dp(con[pos][1],modo);
}else {
ans=std::min(ans,dp(con[pos][0],modo));
ans=std::min(ans,dp(con[pos][1],modo));
}
}
return tab[pos][modo]=ans;
}
///Left -> valores menores que obj, Right -> valores maiores que obj
int left,right,objetivo;
int marcas[MAX];
void dfs(int pos){
if(!types[pos]){///Eh folha
int inicio=left+1;
int fim = (N-right);
marcas[inicio]++;
marcas[fim+1]--;
return;
}
if(types[pos]==MINIMO){///Temos que ter um valor = X e outro maior que X
int esq = dp(con[pos][0],1),dir = dp(con[pos][1],1);
right+=esq;
dfs(con[pos][1]);
right+=-esq+dir;
dfs(con[pos][0]);
right+=-dir;
}else if(types[pos]==MAXIMO){///Temos que ter um valor = X e outro menor que X
int esq = dp(con[pos][0],0),dir = dp(con[pos][1],0);
left+=esq;
dfs(con[pos][1]);
left+=-esq+dir;
dfs(con[pos][0]);
left+=-dir;
}
return;
}
int main()
{
std::string s;
std::cin>>s;
for(auto&x:s)if(x=='?')++N;
///Destrinchar
std::vector<int> stack;
int cur=0;
for(int i=0;i<s.size();++i){
if(s[i]==',')continue;
if(s[i]==')'){
stack.pop_back();
continue;
}
if(s[i]=='?'){
con[stack.back()].push_back(cur);
++cur;
continue;
}
if(s[i]=='m'){
if(stack.size())
con[stack.back()].push_back(cur);
int tipo=MINIMO;
if(s[i+1]=='a')tipo=MAXIMO;
i+=3;
stack.push_back(cur);
types[cur]=tipo;
++cur;
}else std::cout<<s[i];
}
dfs(0);
int count=0,curs=0;
for(int i=1;i<=N;++i){
curs+=marcas[i];
if(curs)++count;
}
std::cout<<count<<"\n";
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:77:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int i=0;i<s.size();++i){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2772 KB |
Output is correct |
2 |
Correct |
1 ms |
2772 KB |
Output is correct |
3 |
Correct |
1 ms |
2772 KB |
Output is correct |
4 |
Correct |
1 ms |
2772 KB |
Output is correct |
5 |
Correct |
1 ms |
2780 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
2 ms |
2772 KB |
Output is correct |
10 |
Correct |
2 ms |
2776 KB |
Output is correct |
11 |
Correct |
1 ms |
2772 KB |
Output is correct |
12 |
Correct |
2 ms |
2788 KB |
Output is correct |
13 |
Correct |
1 ms |
2772 KB |
Output is correct |
14 |
Correct |
2 ms |
2772 KB |
Output is correct |
15 |
Correct |
2 ms |
2772 KB |
Output is correct |
16 |
Correct |
2 ms |
2772 KB |
Output is correct |
17 |
Correct |
2 ms |
2772 KB |
Output is correct |
18 |
Correct |
2 ms |
2772 KB |
Output is correct |
19 |
Correct |
1 ms |
2772 KB |
Output is correct |
20 |
Correct |
2 ms |
2772 KB |
Output is correct |
21 |
Correct |
2 ms |
2772 KB |
Output is correct |
22 |
Correct |
2 ms |
2772 KB |
Output is correct |
23 |
Correct |
1 ms |
2772 KB |
Output is correct |
24 |
Correct |
2 ms |
2772 KB |
Output is correct |
25 |
Correct |
2 ms |
2772 KB |
Output is correct |
26 |
Correct |
2 ms |
2772 KB |
Output is correct |
27 |
Correct |
2 ms |
2780 KB |
Output is correct |
28 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2772 KB |
Output is correct |
2 |
Correct |
1 ms |
2772 KB |
Output is correct |
3 |
Correct |
1 ms |
2772 KB |
Output is correct |
4 |
Correct |
1 ms |
2772 KB |
Output is correct |
5 |
Correct |
1 ms |
2780 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
2 ms |
2772 KB |
Output is correct |
10 |
Correct |
2 ms |
2776 KB |
Output is correct |
11 |
Correct |
1 ms |
2772 KB |
Output is correct |
12 |
Correct |
2 ms |
2788 KB |
Output is correct |
13 |
Correct |
1 ms |
2772 KB |
Output is correct |
14 |
Correct |
2 ms |
2772 KB |
Output is correct |
15 |
Correct |
2 ms |
2772 KB |
Output is correct |
16 |
Correct |
2 ms |
2772 KB |
Output is correct |
17 |
Correct |
2 ms |
2772 KB |
Output is correct |
18 |
Correct |
2 ms |
2772 KB |
Output is correct |
19 |
Correct |
1 ms |
2772 KB |
Output is correct |
20 |
Correct |
2 ms |
2772 KB |
Output is correct |
21 |
Correct |
2 ms |
2772 KB |
Output is correct |
22 |
Correct |
2 ms |
2772 KB |
Output is correct |
23 |
Correct |
1 ms |
2772 KB |
Output is correct |
24 |
Correct |
2 ms |
2772 KB |
Output is correct |
25 |
Correct |
2 ms |
2772 KB |
Output is correct |
26 |
Correct |
2 ms |
2772 KB |
Output is correct |
27 |
Correct |
2 ms |
2780 KB |
Output is correct |
28 |
Correct |
2 ms |
2772 KB |
Output is correct |
29 |
Correct |
2 ms |
2772 KB |
Output is correct |
30 |
Correct |
2 ms |
2772 KB |
Output is correct |
31 |
Correct |
2 ms |
2772 KB |
Output is correct |
32 |
Correct |
2 ms |
2772 KB |
Output is correct |
33 |
Correct |
1 ms |
2772 KB |
Output is correct |
34 |
Correct |
2 ms |
2780 KB |
Output is correct |
35 |
Correct |
2 ms |
2900 KB |
Output is correct |
36 |
Correct |
2 ms |
2776 KB |
Output is correct |
37 |
Correct |
2 ms |
2732 KB |
Output is correct |
38 |
Correct |
2 ms |
2772 KB |
Output is correct |
39 |
Correct |
2 ms |
2776 KB |
Output is correct |
40 |
Correct |
2 ms |
2772 KB |
Output is correct |
41 |
Correct |
1 ms |
2772 KB |
Output is correct |
42 |
Correct |
2 ms |
2776 KB |
Output is correct |
43 |
Correct |
2 ms |
2772 KB |
Output is correct |
44 |
Correct |
2 ms |
2772 KB |
Output is correct |
45 |
Correct |
2 ms |
2772 KB |
Output is correct |
46 |
Correct |
2 ms |
2780 KB |
Output is correct |
47 |
Correct |
2 ms |
2772 KB |
Output is correct |
48 |
Correct |
2 ms |
2776 KB |
Output is correct |
49 |
Correct |
2 ms |
2784 KB |
Output is correct |
50 |
Correct |
2 ms |
2772 KB |
Output is correct |
51 |
Correct |
1 ms |
2772 KB |
Output is correct |
52 |
Correct |
2 ms |
2772 KB |
Output is correct |
53 |
Correct |
2 ms |
2772 KB |
Output is correct |
54 |
Correct |
2 ms |
2772 KB |
Output is correct |
55 |
Correct |
2 ms |
2772 KB |
Output is correct |
56 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
167 ms |
25680 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2772 KB |
Output is correct |
2 |
Correct |
1 ms |
2772 KB |
Output is correct |
3 |
Correct |
1 ms |
2772 KB |
Output is correct |
4 |
Correct |
1 ms |
2772 KB |
Output is correct |
5 |
Correct |
1 ms |
2780 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
2 ms |
2772 KB |
Output is correct |
10 |
Correct |
2 ms |
2776 KB |
Output is correct |
11 |
Correct |
1 ms |
2772 KB |
Output is correct |
12 |
Correct |
2 ms |
2788 KB |
Output is correct |
13 |
Correct |
1 ms |
2772 KB |
Output is correct |
14 |
Correct |
2 ms |
2772 KB |
Output is correct |
15 |
Correct |
2 ms |
2772 KB |
Output is correct |
16 |
Correct |
2 ms |
2772 KB |
Output is correct |
17 |
Correct |
2 ms |
2772 KB |
Output is correct |
18 |
Correct |
2 ms |
2772 KB |
Output is correct |
19 |
Correct |
1 ms |
2772 KB |
Output is correct |
20 |
Correct |
2 ms |
2772 KB |
Output is correct |
21 |
Correct |
2 ms |
2772 KB |
Output is correct |
22 |
Correct |
2 ms |
2772 KB |
Output is correct |
23 |
Correct |
1 ms |
2772 KB |
Output is correct |
24 |
Correct |
2 ms |
2772 KB |
Output is correct |
25 |
Correct |
2 ms |
2772 KB |
Output is correct |
26 |
Correct |
2 ms |
2772 KB |
Output is correct |
27 |
Correct |
2 ms |
2780 KB |
Output is correct |
28 |
Correct |
2 ms |
2772 KB |
Output is correct |
29 |
Correct |
2 ms |
2772 KB |
Output is correct |
30 |
Correct |
2 ms |
2772 KB |
Output is correct |
31 |
Correct |
2 ms |
2772 KB |
Output is correct |
32 |
Correct |
2 ms |
2772 KB |
Output is correct |
33 |
Correct |
1 ms |
2772 KB |
Output is correct |
34 |
Correct |
2 ms |
2780 KB |
Output is correct |
35 |
Correct |
2 ms |
2900 KB |
Output is correct |
36 |
Correct |
2 ms |
2776 KB |
Output is correct |
37 |
Correct |
2 ms |
2732 KB |
Output is correct |
38 |
Correct |
2 ms |
2772 KB |
Output is correct |
39 |
Correct |
2 ms |
2776 KB |
Output is correct |
40 |
Correct |
2 ms |
2772 KB |
Output is correct |
41 |
Correct |
1 ms |
2772 KB |
Output is correct |
42 |
Correct |
2 ms |
2776 KB |
Output is correct |
43 |
Correct |
2 ms |
2772 KB |
Output is correct |
44 |
Correct |
2 ms |
2772 KB |
Output is correct |
45 |
Correct |
2 ms |
2772 KB |
Output is correct |
46 |
Correct |
2 ms |
2780 KB |
Output is correct |
47 |
Correct |
2 ms |
2772 KB |
Output is correct |
48 |
Correct |
2 ms |
2776 KB |
Output is correct |
49 |
Correct |
2 ms |
2784 KB |
Output is correct |
50 |
Correct |
2 ms |
2772 KB |
Output is correct |
51 |
Correct |
1 ms |
2772 KB |
Output is correct |
52 |
Correct |
2 ms |
2772 KB |
Output is correct |
53 |
Correct |
2 ms |
2772 KB |
Output is correct |
54 |
Correct |
2 ms |
2772 KB |
Output is correct |
55 |
Correct |
2 ms |
2772 KB |
Output is correct |
56 |
Correct |
2 ms |
2772 KB |
Output is correct |
57 |
Correct |
2 ms |
2772 KB |
Output is correct |
58 |
Correct |
2 ms |
2780 KB |
Output is correct |
59 |
Correct |
2 ms |
2772 KB |
Output is correct |
60 |
Correct |
2 ms |
2772 KB |
Output is correct |
61 |
Correct |
2 ms |
2772 KB |
Output is correct |
62 |
Correct |
2 ms |
2784 KB |
Output is correct |
63 |
Correct |
2 ms |
2784 KB |
Output is correct |
64 |
Correct |
2 ms |
2780 KB |
Output is correct |
65 |
Correct |
3 ms |
2772 KB |
Output is correct |
66 |
Correct |
2 ms |
2900 KB |
Output is correct |
67 |
Correct |
2 ms |
2776 KB |
Output is correct |
68 |
Correct |
2 ms |
2772 KB |
Output is correct |
69 |
Correct |
2 ms |
2772 KB |
Output is correct |
70 |
Correct |
2 ms |
2780 KB |
Output is correct |
71 |
Correct |
2 ms |
2772 KB |
Output is correct |
72 |
Correct |
2 ms |
2900 KB |
Output is correct |
73 |
Correct |
2 ms |
2900 KB |
Output is correct |
74 |
Correct |
2 ms |
2904 KB |
Output is correct |
75 |
Correct |
2 ms |
2908 KB |
Output is correct |
76 |
Correct |
2 ms |
2904 KB |
Output is correct |
77 |
Correct |
2 ms |
2776 KB |
Output is correct |
78 |
Correct |
2 ms |
2828 KB |
Output is correct |
79 |
Correct |
3 ms |
2772 KB |
Output is correct |
80 |
Correct |
2 ms |
2772 KB |
Output is correct |
81 |
Correct |
2 ms |
2900 KB |
Output is correct |
82 |
Correct |
2 ms |
2900 KB |
Output is correct |
83 |
Correct |
3 ms |
2772 KB |
Output is correct |
84 |
Correct |
2 ms |
2772 KB |
Output is correct |
85 |
Correct |
2 ms |
2780 KB |
Output is correct |
86 |
Correct |
2 ms |
2772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2772 KB |
Output is correct |
2 |
Correct |
1 ms |
2772 KB |
Output is correct |
3 |
Correct |
1 ms |
2772 KB |
Output is correct |
4 |
Correct |
1 ms |
2772 KB |
Output is correct |
5 |
Correct |
1 ms |
2780 KB |
Output is correct |
6 |
Correct |
2 ms |
2772 KB |
Output is correct |
7 |
Correct |
2 ms |
2772 KB |
Output is correct |
8 |
Correct |
2 ms |
2772 KB |
Output is correct |
9 |
Correct |
2 ms |
2772 KB |
Output is correct |
10 |
Correct |
2 ms |
2776 KB |
Output is correct |
11 |
Correct |
1 ms |
2772 KB |
Output is correct |
12 |
Correct |
2 ms |
2788 KB |
Output is correct |
13 |
Correct |
1 ms |
2772 KB |
Output is correct |
14 |
Correct |
2 ms |
2772 KB |
Output is correct |
15 |
Correct |
2 ms |
2772 KB |
Output is correct |
16 |
Correct |
2 ms |
2772 KB |
Output is correct |
17 |
Correct |
2 ms |
2772 KB |
Output is correct |
18 |
Correct |
2 ms |
2772 KB |
Output is correct |
19 |
Correct |
1 ms |
2772 KB |
Output is correct |
20 |
Correct |
2 ms |
2772 KB |
Output is correct |
21 |
Correct |
2 ms |
2772 KB |
Output is correct |
22 |
Correct |
2 ms |
2772 KB |
Output is correct |
23 |
Correct |
1 ms |
2772 KB |
Output is correct |
24 |
Correct |
2 ms |
2772 KB |
Output is correct |
25 |
Correct |
2 ms |
2772 KB |
Output is correct |
26 |
Correct |
2 ms |
2772 KB |
Output is correct |
27 |
Correct |
2 ms |
2780 KB |
Output is correct |
28 |
Correct |
2 ms |
2772 KB |
Output is correct |
29 |
Correct |
2 ms |
2772 KB |
Output is correct |
30 |
Correct |
2 ms |
2772 KB |
Output is correct |
31 |
Correct |
2 ms |
2772 KB |
Output is correct |
32 |
Correct |
2 ms |
2772 KB |
Output is correct |
33 |
Correct |
1 ms |
2772 KB |
Output is correct |
34 |
Correct |
2 ms |
2780 KB |
Output is correct |
35 |
Correct |
2 ms |
2900 KB |
Output is correct |
36 |
Correct |
2 ms |
2776 KB |
Output is correct |
37 |
Correct |
2 ms |
2732 KB |
Output is correct |
38 |
Correct |
2 ms |
2772 KB |
Output is correct |
39 |
Correct |
2 ms |
2776 KB |
Output is correct |
40 |
Correct |
2 ms |
2772 KB |
Output is correct |
41 |
Correct |
1 ms |
2772 KB |
Output is correct |
42 |
Correct |
2 ms |
2776 KB |
Output is correct |
43 |
Correct |
2 ms |
2772 KB |
Output is correct |
44 |
Correct |
2 ms |
2772 KB |
Output is correct |
45 |
Correct |
2 ms |
2772 KB |
Output is correct |
46 |
Correct |
2 ms |
2780 KB |
Output is correct |
47 |
Correct |
2 ms |
2772 KB |
Output is correct |
48 |
Correct |
2 ms |
2776 KB |
Output is correct |
49 |
Correct |
2 ms |
2784 KB |
Output is correct |
50 |
Correct |
2 ms |
2772 KB |
Output is correct |
51 |
Correct |
1 ms |
2772 KB |
Output is correct |
52 |
Correct |
2 ms |
2772 KB |
Output is correct |
53 |
Correct |
2 ms |
2772 KB |
Output is correct |
54 |
Correct |
2 ms |
2772 KB |
Output is correct |
55 |
Correct |
2 ms |
2772 KB |
Output is correct |
56 |
Correct |
2 ms |
2772 KB |
Output is correct |
57 |
Runtime error |
167 ms |
25680 KB |
Execution killed with signal 11 |
58 |
Halted |
0 ms |
0 KB |
- |