Submission #750241

# Submission time Handle Problem Language Result Execution time Memory
750241 2023-05-29T08:31:25 Z MetalPower Homework (CEOI22_homework) C++14
100 / 100
242 ms 205868 KB
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int, int>
#define fi first
#define se second

const int MX = 2e6 + 10;

string s;

int tim = 0, tp[MX], lf[MX], rg[MX], sub[MX];
vector<int> st, adj[MX];

void dp(int idx){
	if(tp[idx] == 0){
		sub[idx] = lf[idx] = rg[idx] = 1;
	}else{
		for(int nxt : adj[idx]){
			dp(nxt);
			sub[idx] += sub[nxt];
		}
		if(tp[idx] == 1){ // max
			lf[idx] = lf[adj[idx][0]] + lf[adj[idx][1]];
			rg[idx] = max(sub[adj[idx][0]] + rg[adj[idx][1]], sub[adj[idx][1]] + rg[adj[idx][0]]);
		}else{ // min
			lf[idx] = min(lf[adj[idx][0]], lf[adj[idx][1]]);
			rg[idx] = rg[adj[idx][0]] + rg[adj[idx][1]] - 1;
		}
	}
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> s;

	for(int i = 0; i < (int) s.length(); ){
		if(s[i] == '(' || s[i] == ','){
			i++;
		}else if(s[i] == 'm'){
			if(s[i + 1] == 'a'){
				++tim;
				tp[tim] = 1;
				if(!st.empty()) adj[st.back()].push_back(tim);
				st.push_back(tim);
			}else{
				++tim;
				tp[tim] = 2;
				if(!st.empty()) adj[st.back()].push_back(tim);
				st.push_back(tim);
			}
			i += 3;
		}else if(s[i] == '?'){
			++tim;
			tp[tim] = 0;
			adj[st.back()].push_back(tim);
			i++;
		}else if(s[i] == ')'){
			st.pop_back();
			i++;
		}
	}

	dp(1);
	cout << rg[1] - lf[1] + 1 << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47312 KB Output is correct
2 Correct 29 ms 47292 KB Output is correct
3 Correct 28 ms 47280 KB Output is correct
4 Correct 26 ms 47292 KB Output is correct
5 Correct 31 ms 47216 KB Output is correct
6 Correct 31 ms 47316 KB Output is correct
7 Correct 27 ms 47312 KB Output is correct
8 Correct 27 ms 47188 KB Output is correct
9 Correct 25 ms 47188 KB Output is correct
10 Correct 25 ms 47212 KB Output is correct
11 Correct 26 ms 47180 KB Output is correct
12 Correct 24 ms 47276 KB Output is correct
13 Correct 25 ms 47208 KB Output is correct
14 Correct 25 ms 47188 KB Output is correct
15 Correct 28 ms 47292 KB Output is correct
16 Correct 27 ms 47220 KB Output is correct
17 Correct 34 ms 47200 KB Output is correct
18 Correct 29 ms 47320 KB Output is correct
19 Correct 27 ms 47324 KB Output is correct
20 Correct 27 ms 47308 KB Output is correct
21 Correct 25 ms 47316 KB Output is correct
22 Correct 25 ms 47316 KB Output is correct
23 Correct 25 ms 47272 KB Output is correct
24 Correct 24 ms 47292 KB Output is correct
25 Correct 25 ms 47304 KB Output is correct
26 Correct 25 ms 47188 KB Output is correct
27 Correct 29 ms 47292 KB Output is correct
28 Correct 28 ms 47436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47312 KB Output is correct
2 Correct 29 ms 47292 KB Output is correct
3 Correct 28 ms 47280 KB Output is correct
4 Correct 26 ms 47292 KB Output is correct
5 Correct 31 ms 47216 KB Output is correct
6 Correct 31 ms 47316 KB Output is correct
7 Correct 27 ms 47312 KB Output is correct
8 Correct 27 ms 47188 KB Output is correct
9 Correct 25 ms 47188 KB Output is correct
10 Correct 25 ms 47212 KB Output is correct
11 Correct 26 ms 47180 KB Output is correct
12 Correct 24 ms 47276 KB Output is correct
13 Correct 25 ms 47208 KB Output is correct
14 Correct 25 ms 47188 KB Output is correct
15 Correct 28 ms 47292 KB Output is correct
16 Correct 27 ms 47220 KB Output is correct
17 Correct 34 ms 47200 KB Output is correct
18 Correct 29 ms 47320 KB Output is correct
19 Correct 27 ms 47324 KB Output is correct
20 Correct 27 ms 47308 KB Output is correct
21 Correct 25 ms 47316 KB Output is correct
22 Correct 25 ms 47316 KB Output is correct
23 Correct 25 ms 47272 KB Output is correct
24 Correct 24 ms 47292 KB Output is correct
25 Correct 25 ms 47304 KB Output is correct
26 Correct 25 ms 47188 KB Output is correct
27 Correct 29 ms 47292 KB Output is correct
28 Correct 28 ms 47436 KB Output is correct
29 Correct 26 ms 47300 KB Output is correct
30 Correct 25 ms 47204 KB Output is correct
31 Correct 26 ms 47284 KB Output is correct
32 Correct 25 ms 47296 KB Output is correct
33 Correct 28 ms 47256 KB Output is correct
34 Correct 29 ms 47308 KB Output is correct
35 Correct 26 ms 47272 KB Output is correct
36 Correct 28 ms 47180 KB Output is correct
37 Correct 25 ms 47304 KB Output is correct
38 Correct 31 ms 47308 KB Output is correct
39 Correct 26 ms 47264 KB Output is correct
40 Correct 26 ms 47264 KB Output is correct
41 Correct 24 ms 47288 KB Output is correct
42 Correct 26 ms 47180 KB Output is correct
43 Correct 27 ms 47300 KB Output is correct
44 Correct 30 ms 47300 KB Output is correct
45 Correct 28 ms 47220 KB Output is correct
46 Correct 25 ms 47220 KB Output is correct
47 Correct 25 ms 47280 KB Output is correct
48 Correct 26 ms 47228 KB Output is correct
49 Correct 25 ms 47332 KB Output is correct
50 Correct 26 ms 47260 KB Output is correct
51 Correct 26 ms 47316 KB Output is correct
52 Correct 27 ms 47296 KB Output is correct
53 Correct 28 ms 47188 KB Output is correct
54 Correct 26 ms 47296 KB Output is correct
55 Correct 25 ms 47300 KB Output is correct
56 Correct 31 ms 47276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 240 ms 205724 KB Output is correct
2 Correct 229 ms 205676 KB Output is correct
3 Correct 229 ms 205828 KB Output is correct
4 Correct 236 ms 205860 KB Output is correct
5 Correct 235 ms 205708 KB Output is correct
6 Correct 239 ms 205708 KB Output is correct
7 Correct 223 ms 205688 KB Output is correct
8 Correct 223 ms 205748 KB Output is correct
9 Correct 230 ms 205848 KB Output is correct
10 Correct 230 ms 205780 KB Output is correct
11 Correct 221 ms 205704 KB Output is correct
12 Correct 231 ms 205708 KB Output is correct
13 Correct 26 ms 47200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47312 KB Output is correct
2 Correct 29 ms 47292 KB Output is correct
3 Correct 28 ms 47280 KB Output is correct
4 Correct 26 ms 47292 KB Output is correct
5 Correct 31 ms 47216 KB Output is correct
6 Correct 31 ms 47316 KB Output is correct
7 Correct 27 ms 47312 KB Output is correct
8 Correct 27 ms 47188 KB Output is correct
9 Correct 25 ms 47188 KB Output is correct
10 Correct 25 ms 47212 KB Output is correct
11 Correct 26 ms 47180 KB Output is correct
12 Correct 24 ms 47276 KB Output is correct
13 Correct 25 ms 47208 KB Output is correct
14 Correct 25 ms 47188 KB Output is correct
15 Correct 28 ms 47292 KB Output is correct
16 Correct 27 ms 47220 KB Output is correct
17 Correct 34 ms 47200 KB Output is correct
18 Correct 29 ms 47320 KB Output is correct
19 Correct 27 ms 47324 KB Output is correct
20 Correct 27 ms 47308 KB Output is correct
21 Correct 25 ms 47316 KB Output is correct
22 Correct 25 ms 47316 KB Output is correct
23 Correct 25 ms 47272 KB Output is correct
24 Correct 24 ms 47292 KB Output is correct
25 Correct 25 ms 47304 KB Output is correct
26 Correct 25 ms 47188 KB Output is correct
27 Correct 29 ms 47292 KB Output is correct
28 Correct 28 ms 47436 KB Output is correct
29 Correct 26 ms 47300 KB Output is correct
30 Correct 25 ms 47204 KB Output is correct
31 Correct 26 ms 47284 KB Output is correct
32 Correct 25 ms 47296 KB Output is correct
33 Correct 28 ms 47256 KB Output is correct
34 Correct 29 ms 47308 KB Output is correct
35 Correct 26 ms 47272 KB Output is correct
36 Correct 28 ms 47180 KB Output is correct
37 Correct 25 ms 47304 KB Output is correct
38 Correct 31 ms 47308 KB Output is correct
39 Correct 26 ms 47264 KB Output is correct
40 Correct 26 ms 47264 KB Output is correct
41 Correct 24 ms 47288 KB Output is correct
42 Correct 26 ms 47180 KB Output is correct
43 Correct 27 ms 47300 KB Output is correct
44 Correct 30 ms 47300 KB Output is correct
45 Correct 28 ms 47220 KB Output is correct
46 Correct 25 ms 47220 KB Output is correct
47 Correct 25 ms 47280 KB Output is correct
48 Correct 26 ms 47228 KB Output is correct
49 Correct 25 ms 47332 KB Output is correct
50 Correct 26 ms 47260 KB Output is correct
51 Correct 26 ms 47316 KB Output is correct
52 Correct 27 ms 47296 KB Output is correct
53 Correct 28 ms 47188 KB Output is correct
54 Correct 26 ms 47296 KB Output is correct
55 Correct 25 ms 47300 KB Output is correct
56 Correct 31 ms 47276 KB Output is correct
57 Correct 24 ms 47284 KB Output is correct
58 Correct 26 ms 47300 KB Output is correct
59 Correct 26 ms 47284 KB Output is correct
60 Correct 29 ms 47288 KB Output is correct
61 Correct 31 ms 47328 KB Output is correct
62 Correct 28 ms 47308 KB Output is correct
63 Correct 31 ms 47316 KB Output is correct
64 Correct 26 ms 47432 KB Output is correct
65 Correct 26 ms 47352 KB Output is correct
66 Correct 32 ms 47472 KB Output is correct
67 Correct 25 ms 47316 KB Output is correct
68 Correct 28 ms 47332 KB Output is correct
69 Correct 29 ms 47316 KB Output is correct
70 Correct 32 ms 47372 KB Output is correct
71 Correct 28 ms 47380 KB Output is correct
72 Correct 27 ms 47472 KB Output is correct
73 Correct 26 ms 47420 KB Output is correct
74 Correct 25 ms 47408 KB Output is correct
75 Correct 27 ms 47396 KB Output is correct
76 Correct 25 ms 47444 KB Output is correct
77 Correct 24 ms 47380 KB Output is correct
78 Correct 25 ms 47308 KB Output is correct
79 Correct 26 ms 47316 KB Output is correct
80 Correct 25 ms 47316 KB Output is correct
81 Correct 26 ms 47436 KB Output is correct
82 Correct 26 ms 47432 KB Output is correct
83 Correct 30 ms 47228 KB Output is correct
84 Correct 27 ms 47308 KB Output is correct
85 Correct 29 ms 47228 KB Output is correct
86 Correct 25 ms 47284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47312 KB Output is correct
2 Correct 29 ms 47292 KB Output is correct
3 Correct 28 ms 47280 KB Output is correct
4 Correct 26 ms 47292 KB Output is correct
5 Correct 31 ms 47216 KB Output is correct
6 Correct 31 ms 47316 KB Output is correct
7 Correct 27 ms 47312 KB Output is correct
8 Correct 27 ms 47188 KB Output is correct
9 Correct 25 ms 47188 KB Output is correct
10 Correct 25 ms 47212 KB Output is correct
11 Correct 26 ms 47180 KB Output is correct
12 Correct 24 ms 47276 KB Output is correct
13 Correct 25 ms 47208 KB Output is correct
14 Correct 25 ms 47188 KB Output is correct
15 Correct 28 ms 47292 KB Output is correct
16 Correct 27 ms 47220 KB Output is correct
17 Correct 34 ms 47200 KB Output is correct
18 Correct 29 ms 47320 KB Output is correct
19 Correct 27 ms 47324 KB Output is correct
20 Correct 27 ms 47308 KB Output is correct
21 Correct 25 ms 47316 KB Output is correct
22 Correct 25 ms 47316 KB Output is correct
23 Correct 25 ms 47272 KB Output is correct
24 Correct 24 ms 47292 KB Output is correct
25 Correct 25 ms 47304 KB Output is correct
26 Correct 25 ms 47188 KB Output is correct
27 Correct 29 ms 47292 KB Output is correct
28 Correct 28 ms 47436 KB Output is correct
29 Correct 26 ms 47300 KB Output is correct
30 Correct 25 ms 47204 KB Output is correct
31 Correct 26 ms 47284 KB Output is correct
32 Correct 25 ms 47296 KB Output is correct
33 Correct 28 ms 47256 KB Output is correct
34 Correct 29 ms 47308 KB Output is correct
35 Correct 26 ms 47272 KB Output is correct
36 Correct 28 ms 47180 KB Output is correct
37 Correct 25 ms 47304 KB Output is correct
38 Correct 31 ms 47308 KB Output is correct
39 Correct 26 ms 47264 KB Output is correct
40 Correct 26 ms 47264 KB Output is correct
41 Correct 24 ms 47288 KB Output is correct
42 Correct 26 ms 47180 KB Output is correct
43 Correct 27 ms 47300 KB Output is correct
44 Correct 30 ms 47300 KB Output is correct
45 Correct 28 ms 47220 KB Output is correct
46 Correct 25 ms 47220 KB Output is correct
47 Correct 25 ms 47280 KB Output is correct
48 Correct 26 ms 47228 KB Output is correct
49 Correct 25 ms 47332 KB Output is correct
50 Correct 26 ms 47260 KB Output is correct
51 Correct 26 ms 47316 KB Output is correct
52 Correct 27 ms 47296 KB Output is correct
53 Correct 28 ms 47188 KB Output is correct
54 Correct 26 ms 47296 KB Output is correct
55 Correct 25 ms 47300 KB Output is correct
56 Correct 31 ms 47276 KB Output is correct
57 Correct 240 ms 205724 KB Output is correct
58 Correct 229 ms 205676 KB Output is correct
59 Correct 229 ms 205828 KB Output is correct
60 Correct 236 ms 205860 KB Output is correct
61 Correct 235 ms 205708 KB Output is correct
62 Correct 239 ms 205708 KB Output is correct
63 Correct 223 ms 205688 KB Output is correct
64 Correct 223 ms 205748 KB Output is correct
65 Correct 230 ms 205848 KB Output is correct
66 Correct 230 ms 205780 KB Output is correct
67 Correct 221 ms 205704 KB Output is correct
68 Correct 231 ms 205708 KB Output is correct
69 Correct 26 ms 47200 KB Output is correct
70 Correct 24 ms 47284 KB Output is correct
71 Correct 26 ms 47300 KB Output is correct
72 Correct 26 ms 47284 KB Output is correct
73 Correct 29 ms 47288 KB Output is correct
74 Correct 31 ms 47328 KB Output is correct
75 Correct 28 ms 47308 KB Output is correct
76 Correct 31 ms 47316 KB Output is correct
77 Correct 26 ms 47432 KB Output is correct
78 Correct 26 ms 47352 KB Output is correct
79 Correct 32 ms 47472 KB Output is correct
80 Correct 25 ms 47316 KB Output is correct
81 Correct 28 ms 47332 KB Output is correct
82 Correct 29 ms 47316 KB Output is correct
83 Correct 32 ms 47372 KB Output is correct
84 Correct 28 ms 47380 KB Output is correct
85 Correct 27 ms 47472 KB Output is correct
86 Correct 26 ms 47420 KB Output is correct
87 Correct 25 ms 47408 KB Output is correct
88 Correct 27 ms 47396 KB Output is correct
89 Correct 25 ms 47444 KB Output is correct
90 Correct 24 ms 47380 KB Output is correct
91 Correct 25 ms 47308 KB Output is correct
92 Correct 26 ms 47316 KB Output is correct
93 Correct 25 ms 47316 KB Output is correct
94 Correct 26 ms 47436 KB Output is correct
95 Correct 26 ms 47432 KB Output is correct
96 Correct 30 ms 47228 KB Output is correct
97 Correct 27 ms 47308 KB Output is correct
98 Correct 29 ms 47228 KB Output is correct
99 Correct 25 ms 47284 KB Output is correct
100 Correct 190 ms 123476 KB Output is correct
101 Correct 185 ms 123512 KB Output is correct
102 Correct 180 ms 123532 KB Output is correct
103 Correct 211 ms 123560 KB Output is correct
104 Correct 177 ms 123532 KB Output is correct
105 Correct 215 ms 150920 KB Output is correct
106 Correct 242 ms 151012 KB Output is correct
107 Correct 206 ms 150936 KB Output is correct
108 Correct 213 ms 150868 KB Output is correct
109 Correct 231 ms 150904 KB Output is correct
110 Correct 193 ms 123528 KB Output is correct
111 Correct 196 ms 123580 KB Output is correct
112 Correct 189 ms 123680 KB Output is correct
113 Correct 182 ms 123624 KB Output is correct
114 Correct 193 ms 123664 KB Output is correct
115 Correct 230 ms 205708 KB Output is correct
116 Correct 242 ms 205728 KB Output is correct
117 Correct 219 ms 205764 KB Output is correct
118 Correct 233 ms 205796 KB Output is correct
119 Correct 220 ms 205868 KB Output is correct
120 Correct 199 ms 123580 KB Output is correct
121 Correct 188 ms 123544 KB Output is correct
122 Correct 202 ms 123644 KB Output is correct
123 Correct 199 ms 123524 KB Output is correct
124 Correct 219 ms 164680 KB Output is correct
125 Correct 207 ms 164588 KB Output is correct
126 Correct 204 ms 164572 KB Output is correct
127 Correct 207 ms 164660 KB Output is correct
128 Correct 108 ms 87244 KB Output is correct
129 Correct 97 ms 87248 KB Output is correct
130 Correct 97 ms 87324 KB Output is correct
131 Correct 27 ms 47308 KB Output is correct