#include "bits/stdc++.h"
#define TREE_SIZE (1<<17)
#define ls (v * 2)
#define rs (v * 2 + 1)
using namespace std;
struct node
{
pair <int, int> value;
string type;
} tree[TREE_SIZE * 2];
string s;
void insert(int v, int mx, int n)
{
tree[v].value = {1, n};
while(v != 0)
{
v /= 2;
if(tree[v].type == "max")
{
tree[v].value = {tree[ls].value.first + tree[rs].value.first, max(tree[ls].value.second, tree[rs].value.second)};
}
if(tree[v].type == "min")
{
tree[v].value = {min(tree[ls].value.first, tree[rs].value.first), tree[ls].value.second + tree[rs].value.second - n - 1};
}
}
}
signed main()
{
cin.tie(0) -> ios_base::sync_with_stdio(0);
cin >> s;
int question_marks = count(s.begin(), s.end(), '?');
vector <int> q;
int mx = 0, mm = 0, it = 1, son = 0;
for(auto u : s)
{
if(u == 'm' || u == 'a' || u == 'i') continue;
if(u == '(') it *= 2;
if(u == ')') it /= 2;
it += son;
int act_son = it;
if(u == ',') son = 1;
else son = 0;
if(u == 'n')
{
tree[act_son].type = "min";
mm++;
}
if(u == 'x')
{
tree[act_son].type = "max";
mx++;
}
if(u == '?')
{
tree[act_son].type = "const";
q.push_back(act_son);
}
}
//for(auto u : q)
// cout << u << ' ';
for(auto u : q)
insert(u, q[q.size() - 1], question_marks);
cout << tree[1].value.second - tree[1].value.first + 1 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
10580 KB |
Output is correct |
2 |
Correct |
5 ms |
10452 KB |
Output is correct |
3 |
Correct |
5 ms |
10580 KB |
Output is correct |
4 |
Correct |
5 ms |
10452 KB |
Output is correct |
5 |
Correct |
5 ms |
10580 KB |
Output is correct |
6 |
Correct |
6 ms |
10452 KB |
Output is correct |
7 |
Correct |
5 ms |
10452 KB |
Output is correct |
8 |
Correct |
5 ms |
10524 KB |
Output is correct |
9 |
Correct |
5 ms |
10580 KB |
Output is correct |
10 |
Correct |
5 ms |
10572 KB |
Output is correct |
11 |
Correct |
6 ms |
10468 KB |
Output is correct |
12 |
Correct |
5 ms |
10452 KB |
Output is correct |
13 |
Correct |
5 ms |
10452 KB |
Output is correct |
14 |
Correct |
5 ms |
10580 KB |
Output is correct |
15 |
Correct |
6 ms |
10528 KB |
Output is correct |
16 |
Correct |
6 ms |
10452 KB |
Output is correct |
17 |
Correct |
6 ms |
10452 KB |
Output is correct |
18 |
Correct |
5 ms |
10452 KB |
Output is correct |
19 |
Correct |
5 ms |
10452 KB |
Output is correct |
20 |
Correct |
5 ms |
10452 KB |
Output is correct |
21 |
Correct |
5 ms |
10452 KB |
Output is correct |
22 |
Correct |
6 ms |
10452 KB |
Output is correct |
23 |
Correct |
6 ms |
10580 KB |
Output is correct |
24 |
Correct |
5 ms |
10452 KB |
Output is correct |
25 |
Correct |
5 ms |
10452 KB |
Output is correct |
26 |
Correct |
6 ms |
10452 KB |
Output is correct |
27 |
Correct |
6 ms |
10452 KB |
Output is correct |
28 |
Correct |
5 ms |
10452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
10580 KB |
Output is correct |
2 |
Correct |
5 ms |
10452 KB |
Output is correct |
3 |
Correct |
5 ms |
10580 KB |
Output is correct |
4 |
Correct |
5 ms |
10452 KB |
Output is correct |
5 |
Correct |
5 ms |
10580 KB |
Output is correct |
6 |
Correct |
6 ms |
10452 KB |
Output is correct |
7 |
Correct |
5 ms |
10452 KB |
Output is correct |
8 |
Correct |
5 ms |
10524 KB |
Output is correct |
9 |
Correct |
5 ms |
10580 KB |
Output is correct |
10 |
Correct |
5 ms |
10572 KB |
Output is correct |
11 |
Correct |
6 ms |
10468 KB |
Output is correct |
12 |
Correct |
5 ms |
10452 KB |
Output is correct |
13 |
Correct |
5 ms |
10452 KB |
Output is correct |
14 |
Correct |
5 ms |
10580 KB |
Output is correct |
15 |
Correct |
6 ms |
10528 KB |
Output is correct |
16 |
Correct |
6 ms |
10452 KB |
Output is correct |
17 |
Correct |
6 ms |
10452 KB |
Output is correct |
18 |
Correct |
5 ms |
10452 KB |
Output is correct |
19 |
Correct |
5 ms |
10452 KB |
Output is correct |
20 |
Correct |
5 ms |
10452 KB |
Output is correct |
21 |
Correct |
5 ms |
10452 KB |
Output is correct |
22 |
Correct |
6 ms |
10452 KB |
Output is correct |
23 |
Correct |
6 ms |
10580 KB |
Output is correct |
24 |
Correct |
5 ms |
10452 KB |
Output is correct |
25 |
Correct |
5 ms |
10452 KB |
Output is correct |
26 |
Correct |
6 ms |
10452 KB |
Output is correct |
27 |
Correct |
6 ms |
10452 KB |
Output is correct |
28 |
Correct |
5 ms |
10452 KB |
Output is correct |
29 |
Correct |
5 ms |
10452 KB |
Output is correct |
30 |
Correct |
5 ms |
10452 KB |
Output is correct |
31 |
Correct |
5 ms |
10452 KB |
Output is correct |
32 |
Correct |
6 ms |
10572 KB |
Output is correct |
33 |
Correct |
5 ms |
10452 KB |
Output is correct |
34 |
Correct |
5 ms |
10452 KB |
Output is correct |
35 |
Correct |
5 ms |
10452 KB |
Output is correct |
36 |
Correct |
5 ms |
10452 KB |
Output is correct |
37 |
Correct |
5 ms |
10452 KB |
Output is correct |
38 |
Correct |
6 ms |
10452 KB |
Output is correct |
39 |
Correct |
5 ms |
10452 KB |
Output is correct |
40 |
Correct |
5 ms |
10524 KB |
Output is correct |
41 |
Correct |
6 ms |
10476 KB |
Output is correct |
42 |
Correct |
5 ms |
10452 KB |
Output is correct |
43 |
Correct |
6 ms |
10452 KB |
Output is correct |
44 |
Correct |
6 ms |
10580 KB |
Output is correct |
45 |
Correct |
5 ms |
10452 KB |
Output is correct |
46 |
Correct |
5 ms |
10580 KB |
Output is correct |
47 |
Correct |
5 ms |
10452 KB |
Output is correct |
48 |
Correct |
5 ms |
10452 KB |
Output is correct |
49 |
Correct |
5 ms |
10452 KB |
Output is correct |
50 |
Correct |
5 ms |
10452 KB |
Output is correct |
51 |
Correct |
5 ms |
10452 KB |
Output is correct |
52 |
Correct |
7 ms |
10580 KB |
Output is correct |
53 |
Correct |
5 ms |
10580 KB |
Output is correct |
54 |
Correct |
6 ms |
10480 KB |
Output is correct |
55 |
Correct |
7 ms |
10452 KB |
Output is correct |
56 |
Correct |
8 ms |
10496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
36 ms |
35296 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
10580 KB |
Output is correct |
2 |
Correct |
5 ms |
10452 KB |
Output is correct |
3 |
Correct |
5 ms |
10580 KB |
Output is correct |
4 |
Correct |
5 ms |
10452 KB |
Output is correct |
5 |
Correct |
5 ms |
10580 KB |
Output is correct |
6 |
Correct |
6 ms |
10452 KB |
Output is correct |
7 |
Correct |
5 ms |
10452 KB |
Output is correct |
8 |
Correct |
5 ms |
10524 KB |
Output is correct |
9 |
Correct |
5 ms |
10580 KB |
Output is correct |
10 |
Correct |
5 ms |
10572 KB |
Output is correct |
11 |
Correct |
6 ms |
10468 KB |
Output is correct |
12 |
Correct |
5 ms |
10452 KB |
Output is correct |
13 |
Correct |
5 ms |
10452 KB |
Output is correct |
14 |
Correct |
5 ms |
10580 KB |
Output is correct |
15 |
Correct |
6 ms |
10528 KB |
Output is correct |
16 |
Correct |
6 ms |
10452 KB |
Output is correct |
17 |
Correct |
6 ms |
10452 KB |
Output is correct |
18 |
Correct |
5 ms |
10452 KB |
Output is correct |
19 |
Correct |
5 ms |
10452 KB |
Output is correct |
20 |
Correct |
5 ms |
10452 KB |
Output is correct |
21 |
Correct |
5 ms |
10452 KB |
Output is correct |
22 |
Correct |
6 ms |
10452 KB |
Output is correct |
23 |
Correct |
6 ms |
10580 KB |
Output is correct |
24 |
Correct |
5 ms |
10452 KB |
Output is correct |
25 |
Correct |
5 ms |
10452 KB |
Output is correct |
26 |
Correct |
6 ms |
10452 KB |
Output is correct |
27 |
Correct |
6 ms |
10452 KB |
Output is correct |
28 |
Correct |
5 ms |
10452 KB |
Output is correct |
29 |
Correct |
5 ms |
10452 KB |
Output is correct |
30 |
Correct |
5 ms |
10452 KB |
Output is correct |
31 |
Correct |
5 ms |
10452 KB |
Output is correct |
32 |
Correct |
6 ms |
10572 KB |
Output is correct |
33 |
Correct |
5 ms |
10452 KB |
Output is correct |
34 |
Correct |
5 ms |
10452 KB |
Output is correct |
35 |
Correct |
5 ms |
10452 KB |
Output is correct |
36 |
Correct |
5 ms |
10452 KB |
Output is correct |
37 |
Correct |
5 ms |
10452 KB |
Output is correct |
38 |
Correct |
6 ms |
10452 KB |
Output is correct |
39 |
Correct |
5 ms |
10452 KB |
Output is correct |
40 |
Correct |
5 ms |
10524 KB |
Output is correct |
41 |
Correct |
6 ms |
10476 KB |
Output is correct |
42 |
Correct |
5 ms |
10452 KB |
Output is correct |
43 |
Correct |
6 ms |
10452 KB |
Output is correct |
44 |
Correct |
6 ms |
10580 KB |
Output is correct |
45 |
Correct |
5 ms |
10452 KB |
Output is correct |
46 |
Correct |
5 ms |
10580 KB |
Output is correct |
47 |
Correct |
5 ms |
10452 KB |
Output is correct |
48 |
Correct |
5 ms |
10452 KB |
Output is correct |
49 |
Correct |
5 ms |
10452 KB |
Output is correct |
50 |
Correct |
5 ms |
10452 KB |
Output is correct |
51 |
Correct |
5 ms |
10452 KB |
Output is correct |
52 |
Correct |
7 ms |
10580 KB |
Output is correct |
53 |
Correct |
5 ms |
10580 KB |
Output is correct |
54 |
Correct |
6 ms |
10480 KB |
Output is correct |
55 |
Correct |
7 ms |
10452 KB |
Output is correct |
56 |
Correct |
8 ms |
10496 KB |
Output is correct |
57 |
Correct |
6 ms |
10584 KB |
Output is correct |
58 |
Correct |
6 ms |
10596 KB |
Output is correct |
59 |
Correct |
6 ms |
10580 KB |
Output is correct |
60 |
Correct |
5 ms |
10580 KB |
Output is correct |
61 |
Correct |
6 ms |
10580 KB |
Output is correct |
62 |
Runtime error |
13 ms |
21204 KB |
Execution killed with signal 11 |
63 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
10580 KB |
Output is correct |
2 |
Correct |
5 ms |
10452 KB |
Output is correct |
3 |
Correct |
5 ms |
10580 KB |
Output is correct |
4 |
Correct |
5 ms |
10452 KB |
Output is correct |
5 |
Correct |
5 ms |
10580 KB |
Output is correct |
6 |
Correct |
6 ms |
10452 KB |
Output is correct |
7 |
Correct |
5 ms |
10452 KB |
Output is correct |
8 |
Correct |
5 ms |
10524 KB |
Output is correct |
9 |
Correct |
5 ms |
10580 KB |
Output is correct |
10 |
Correct |
5 ms |
10572 KB |
Output is correct |
11 |
Correct |
6 ms |
10468 KB |
Output is correct |
12 |
Correct |
5 ms |
10452 KB |
Output is correct |
13 |
Correct |
5 ms |
10452 KB |
Output is correct |
14 |
Correct |
5 ms |
10580 KB |
Output is correct |
15 |
Correct |
6 ms |
10528 KB |
Output is correct |
16 |
Correct |
6 ms |
10452 KB |
Output is correct |
17 |
Correct |
6 ms |
10452 KB |
Output is correct |
18 |
Correct |
5 ms |
10452 KB |
Output is correct |
19 |
Correct |
5 ms |
10452 KB |
Output is correct |
20 |
Correct |
5 ms |
10452 KB |
Output is correct |
21 |
Correct |
5 ms |
10452 KB |
Output is correct |
22 |
Correct |
6 ms |
10452 KB |
Output is correct |
23 |
Correct |
6 ms |
10580 KB |
Output is correct |
24 |
Correct |
5 ms |
10452 KB |
Output is correct |
25 |
Correct |
5 ms |
10452 KB |
Output is correct |
26 |
Correct |
6 ms |
10452 KB |
Output is correct |
27 |
Correct |
6 ms |
10452 KB |
Output is correct |
28 |
Correct |
5 ms |
10452 KB |
Output is correct |
29 |
Correct |
5 ms |
10452 KB |
Output is correct |
30 |
Correct |
5 ms |
10452 KB |
Output is correct |
31 |
Correct |
5 ms |
10452 KB |
Output is correct |
32 |
Correct |
6 ms |
10572 KB |
Output is correct |
33 |
Correct |
5 ms |
10452 KB |
Output is correct |
34 |
Correct |
5 ms |
10452 KB |
Output is correct |
35 |
Correct |
5 ms |
10452 KB |
Output is correct |
36 |
Correct |
5 ms |
10452 KB |
Output is correct |
37 |
Correct |
5 ms |
10452 KB |
Output is correct |
38 |
Correct |
6 ms |
10452 KB |
Output is correct |
39 |
Correct |
5 ms |
10452 KB |
Output is correct |
40 |
Correct |
5 ms |
10524 KB |
Output is correct |
41 |
Correct |
6 ms |
10476 KB |
Output is correct |
42 |
Correct |
5 ms |
10452 KB |
Output is correct |
43 |
Correct |
6 ms |
10452 KB |
Output is correct |
44 |
Correct |
6 ms |
10580 KB |
Output is correct |
45 |
Correct |
5 ms |
10452 KB |
Output is correct |
46 |
Correct |
5 ms |
10580 KB |
Output is correct |
47 |
Correct |
5 ms |
10452 KB |
Output is correct |
48 |
Correct |
5 ms |
10452 KB |
Output is correct |
49 |
Correct |
5 ms |
10452 KB |
Output is correct |
50 |
Correct |
5 ms |
10452 KB |
Output is correct |
51 |
Correct |
5 ms |
10452 KB |
Output is correct |
52 |
Correct |
7 ms |
10580 KB |
Output is correct |
53 |
Correct |
5 ms |
10580 KB |
Output is correct |
54 |
Correct |
6 ms |
10480 KB |
Output is correct |
55 |
Correct |
7 ms |
10452 KB |
Output is correct |
56 |
Correct |
8 ms |
10496 KB |
Output is correct |
57 |
Runtime error |
36 ms |
35296 KB |
Execution killed with signal 11 |
58 |
Halted |
0 ms |
0 KB |
- |