Submission #789140

# Submission time Handle Problem Language Result Execution time Memory
789140 2023-07-21T06:14:36 Z ymm Homework (CEOI22_homework) C++17
100 / 100
150 ms 139364 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
typedef long long ll;
typedef std::pair<int,int> pii;
using namespace std;

struct node {
	int op;
	node *l, *r;
};

node *parse(string s)
{
	vector<node *> vec;
	vec.push_back(new node {-2, 0, 0});
	node **nxt = &vec.back()->l;
	int p = 0;
	while (p < s.size()) {
		if (s[p] == '?') {
			*nxt = new node {-1, 0, 0};
			nxt = &vec.back()->r;
			++p;
		} else if (s[p] == ',') {
			++p;
		} else if (s[p] == ')') {
			vec.pop_back();
			nxt = &vec.back()->r;
			++p;
		} else if (s[p+1] == 'i') {
			*nxt = new node {0, 0, 0};
			vec.push_back(*nxt);
			nxt = &vec.back()->l;
			p += 4;
		} else if (s[p+1] == 'a') {
			*nxt = new node {1, 0, 0};
			vec.push_back(*nxt);
			nxt = &vec.back()->l;
			p += 4;
		} else {
			assert(!"bad expression");
		}
	}
	auto ans = vec.back()->l;
	delete(vec.back());
	return ans;
}

tuple<int,int,int> solve(node *v)
{
	if (v->op == -1)
		return {0, 0, 1};
	auto [x1, y1, c1] = solve(v->l);
	auto [x2, y2, c2] = solve(v->r);
	if (v->op == 0)
		return {min(x1, x2), y1 + y2, c1 + c2};
	else
		return {x1 + x2 + 1, c1 + c2 - min(c1 - y1, c2 - y2), c1 + c2};
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	string s;
	cin >> s;
	node *v = parse(s);
	auto [x, y, cnt] = solve(v);
	cout << y-x+1 << '\n';
}

Compilation message

Main.cpp: In function 'node* parse(std::string)':
Main.cpp:18:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  while (p < s.size()) {
      |         ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 320 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 0 ms 316 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 320 KB Output is correct
20 Correct 0 ms 320 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 320 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 0 ms 316 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 320 KB Output is correct
20 Correct 0 ms 320 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 320 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 316 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 288 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 320 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 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 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 ms 316 KB Output is correct
52 Correct 0 ms 324 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 139264 KB Output is correct
2 Correct 129 ms 139216 KB Output is correct
3 Correct 134 ms 139212 KB Output is correct
4 Correct 130 ms 139264 KB Output is correct
5 Correct 124 ms 139192 KB Output is correct
6 Correct 124 ms 139212 KB Output is correct
7 Correct 122 ms 139204 KB Output is correct
8 Correct 131 ms 139140 KB Output is correct
9 Correct 138 ms 139180 KB Output is correct
10 Correct 130 ms 139268 KB Output is correct
11 Correct 126 ms 139236 KB Output is correct
12 Correct 126 ms 139216 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 320 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 0 ms 316 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 320 KB Output is correct
20 Correct 0 ms 320 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 320 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 316 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 288 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 320 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 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 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 ms 316 KB Output is correct
52 Correct 0 ms 324 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 1 ms 324 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 336 KB Output is correct
66 Correct 1 ms 340 KB Output is correct
67 Correct 1 ms 324 KB Output is correct
68 Correct 1 ms 328 KB Output is correct
69 Correct 1 ms 324 KB Output is correct
70 Correct 0 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 452 KB Output is correct
76 Correct 1 ms 468 KB Output is correct
77 Correct 1 ms 320 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 0 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 0 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 0 ms 340 KB Output is correct
86 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 316 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 320 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 0 ms 316 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 320 KB Output is correct
20 Correct 0 ms 320 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 320 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 316 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 288 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 320 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 212 KB Output is correct
44 Correct 1 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 0 ms 212 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 ms 316 KB Output is correct
52 Correct 0 ms 324 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 1 ms 212 KB Output is correct
57 Correct 129 ms 139264 KB Output is correct
58 Correct 129 ms 139216 KB Output is correct
59 Correct 134 ms 139212 KB Output is correct
60 Correct 130 ms 139264 KB Output is correct
61 Correct 124 ms 139192 KB Output is correct
62 Correct 124 ms 139212 KB Output is correct
63 Correct 122 ms 139204 KB Output is correct
64 Correct 131 ms 139140 KB Output is correct
65 Correct 138 ms 139180 KB Output is correct
66 Correct 130 ms 139268 KB Output is correct
67 Correct 126 ms 139236 KB Output is correct
68 Correct 126 ms 139216 KB Output is correct
69 Correct 0 ms 212 KB Output is correct
70 Correct 1 ms 324 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 336 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 324 KB Output is correct
81 Correct 1 ms 328 KB Output is correct
82 Correct 1 ms 324 KB Output is correct
83 Correct 0 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 452 KB Output is correct
89 Correct 1 ms 468 KB Output is correct
90 Correct 1 ms 320 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 0 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 0 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 0 ms 340 KB Output is correct
99 Correct 0 ms 212 KB Output is correct
100 Correct 99 ms 83364 KB Output is correct
101 Correct 100 ms 83388 KB Output is correct
102 Correct 91 ms 83472 KB Output is correct
103 Correct 90 ms 83408 KB Output is correct
104 Correct 87 ms 83464 KB Output is correct
105 Correct 137 ms 97440 KB Output is correct
106 Correct 136 ms 97464 KB Output is correct
107 Correct 121 ms 97440 KB Output is correct
108 Correct 136 ms 97380 KB Output is correct
109 Correct 114 ms 97512 KB Output is correct
110 Correct 103 ms 83468 KB Output is correct
111 Correct 102 ms 83388 KB Output is correct
112 Correct 94 ms 83468 KB Output is correct
113 Correct 95 ms 83352 KB Output is correct
114 Correct 98 ms 83472 KB Output is correct
115 Correct 150 ms 139236 KB Output is correct
116 Correct 142 ms 139200 KB Output is correct
117 Correct 136 ms 139188 KB Output is correct
118 Correct 148 ms 139132 KB Output is correct
119 Correct 145 ms 139364 KB Output is correct
120 Correct 99 ms 83412 KB Output is correct
121 Correct 97 ms 83412 KB Output is correct
122 Correct 114 ms 83448 KB Output is correct
123 Correct 107 ms 83604 KB Output is correct
124 Correct 102 ms 107868 KB Output is correct
125 Correct 101 ms 107916 KB Output is correct
126 Correct 101 ms 107944 KB Output is correct
127 Correct 103 ms 107972 KB Output is correct
128 Correct 61 ms 43852 KB Output is correct
129 Correct 59 ms 43804 KB Output is correct
130 Correct 47 ms 43852 KB Output is correct
131 Correct 0 ms 212 KB Output is correct