Submission #716591

# Submission time Handle Problem Language Result Execution time Memory
716591 2023-03-30T13:21:57 Z Arturgo Homework (CEOI22_homework) C++14
100 / 100
261 ms 149508 KB
#include <bits/stdc++.h>
using namespace std;

struct Vertex {
	int type, l, r;
};

int root = -1;
vector<Vertex> vertices;

int N = 0;

int parse() {
	char car, useless;
	cin >> car;
	
	if(car == '?') {
		int id = vertices.size();
		vertices.push_back({0, -1, -1});
		N++;
		return id;
	}
	
	cin >> car;
	cin >> car;
	cin >> useless;
	int l = parse();
	cin >> useless;
	int r = parse();
	
	cin >> useless;
	int id = vertices.size();
	
	if(car == 'x') {
		vertices.push_back({1, l, r});
	}
	else {
		vertices.push_back({-1, l, r});
	}
	
	return id;
}

struct Ans {
	int lx_l, lx_g, gx_l, gx_g;
};

Ans dyn_ans[2000 * 1000];

Ans calcule_ans(int v) {
	Ans a;
	
	if(vertices[v].type == 0) {
		a = {1, 0, 0, 1};
	}
	else {
		Ans ans_l = calcule_ans(vertices[v].l);
		Ans ans_r = calcule_ans(vertices[v].r);
		
		if(vertices[v].type == 1) {
			a = {
				ans_l.lx_l + ans_r.lx_l,
				ans_l.lx_g + ans_r.lx_g,
				min(ans_l.gx_l, ans_r.gx_l),
				min(ans_l.gx_g, ans_r.gx_g)
			};
		} else {
			a = {
				min(ans_l.lx_l, ans_r.lx_l),
				min(ans_l.lx_g, ans_r.lx_g),
				ans_l.gx_l + ans_r.gx_l,
				ans_l.gx_g + ans_r.gx_g
			};
		}
	}
	
	return dyn_ans[v] = a;
}

/*void debug(int root) {
	if(vertices[root].type == 0) {
		cerr << "?";
		return;
	}
	
	if(vertices[root].type == 1) cerr << "max";
	else cerr << "min";
	
	cerr << "{";
	cerr << dyn_ans[root].lx_l << ",";
	cerr << dyn_ans[root].lx_g << ",";
	cerr << dyn_ans[root].gx_l << ",";
	cerr << dyn_ans[root].gx_g;
	cerr << "}";
	
	cerr << "(";
	debug(vertices[root].l);
	cerr << ",";
	debug(vertices[root].r);
	cerr << ")";
}*/

vector<pair<int, int>> inters;

void gen_inters(int v, int a = 0, int b = 0) {
	if(vertices[v].type == 0) {
		inters.push_back({a, N - b});
	}
	else {
		if(vertices[v].type == 1) {
			gen_inters(
				vertices[v].l,
				a + dyn_ans[vertices[v].r].lx_l,
				b + dyn_ans[vertices[v].r].lx_g
			);
			gen_inters(
				vertices[v].r,
				a + dyn_ans[vertices[v].l].lx_l,
				b + dyn_ans[vertices[v].l].lx_g
			);
		} else {
			gen_inters(
				vertices[v].l,
				a + dyn_ans[vertices[v].r].gx_l,
				b + dyn_ans[vertices[v].r].gx_g
			);
			gen_inters(
				vertices[v].r,
				a + dyn_ans[vertices[v].l].gx_l,
				b + dyn_ans[vertices[v].l].gx_g
			);
		}
	}
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	root = parse();
	calcule_ans(root);
	
	gen_inters(root);
	
	vector<int> vals(N + 1, 0);
	
	for(pair<int, int> inter : inters) {
		vals[inter.first]++;
		vals[inter.second]--;
	}
	
	int sum = 0;
	int nbPossibles = 0;
	
	for(int i = 0;i < N;i++) {
		sum += vals[i];
		if(sum > 0) nbPossibles++;
	}
	
	cout << nbPossibles << endl;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 244 ms 149404 KB Output is correct
2 Correct 252 ms 149440 KB Output is correct
3 Correct 252 ms 149508 KB Output is correct
4 Correct 252 ms 149344 KB Output is correct
5 Correct 251 ms 149508 KB Output is correct
6 Correct 245 ms 149324 KB Output is correct
7 Correct 252 ms 149452 KB Output is correct
8 Correct 245 ms 149436 KB Output is correct
9 Correct 240 ms 149364 KB Output is correct
10 Correct 246 ms 149436 KB Output is correct
11 Correct 244 ms 149428 KB Output is correct
12 Correct 245 ms 149392 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 468 KB Output is correct
73 Correct 1 ms 468 KB Output is correct
74 Correct 1 ms 468 KB Output is correct
75 Correct 1 ms 468 KB Output is correct
76 Correct 1 ms 468 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 0 ms 212 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 244 ms 149404 KB Output is correct
58 Correct 252 ms 149440 KB Output is correct
59 Correct 252 ms 149508 KB Output is correct
60 Correct 252 ms 149344 KB Output is correct
61 Correct 251 ms 149508 KB Output is correct
62 Correct 245 ms 149324 KB Output is correct
63 Correct 252 ms 149452 KB Output is correct
64 Correct 245 ms 149436 KB Output is correct
65 Correct 240 ms 149364 KB Output is correct
66 Correct 246 ms 149436 KB Output is correct
67 Correct 244 ms 149428 KB Output is correct
68 Correct 245 ms 149392 KB Output is correct
69 Correct 0 ms 212 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 1 ms 468 KB Output is correct
86 Correct 1 ms 468 KB Output is correct
87 Correct 1 ms 468 KB Output is correct
88 Correct 1 ms 468 KB Output is correct
89 Correct 1 ms 468 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 1 ms 340 KB Output is correct
93 Correct 1 ms 340 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 1 ms 340 KB Output is correct
97 Correct 1 ms 340 KB Output is correct
98 Correct 1 ms 340 KB Output is correct
99 Correct 1 ms 212 KB Output is correct
100 Correct 235 ms 71196 KB Output is correct
101 Correct 223 ms 71280 KB Output is correct
102 Correct 217 ms 71140 KB Output is correct
103 Correct 199 ms 71116 KB Output is correct
104 Correct 199 ms 71252 KB Output is correct
105 Correct 229 ms 97236 KB Output is correct
106 Correct 215 ms 97212 KB Output is correct
107 Correct 217 ms 97232 KB Output is correct
108 Correct 205 ms 97216 KB Output is correct
109 Correct 216 ms 97220 KB Output is correct
110 Correct 221 ms 71100 KB Output is correct
111 Correct 202 ms 71120 KB Output is correct
112 Correct 213 ms 71108 KB Output is correct
113 Correct 207 ms 71120 KB Output is correct
114 Correct 204 ms 71112 KB Output is correct
115 Correct 254 ms 149404 KB Output is correct
116 Correct 250 ms 149424 KB Output is correct
117 Correct 259 ms 149332 KB Output is correct
118 Correct 242 ms 149492 KB Output is correct
119 Correct 261 ms 149420 KB Output is correct
120 Correct 201 ms 71184 KB Output is correct
121 Correct 198 ms 71180 KB Output is correct
122 Correct 250 ms 71104 KB Output is correct
123 Correct 204 ms 71204 KB Output is correct
124 Correct 215 ms 110328 KB Output is correct
125 Correct 210 ms 110292 KB Output is correct
126 Correct 225 ms 110268 KB Output is correct
127 Correct 214 ms 110252 KB Output is correct
128 Correct 117 ms 37148 KB Output is correct
129 Correct 107 ms 37172 KB Output is correct
130 Correct 105 ms 37144 KB Output is correct
131 Correct 0 ms 212 KB Output is correct