Submission #947500

# Submission time Handle Problem Language Result Execution time Memory
947500 2024-03-16T09:53:29 Z TAhmed33 Homework (CEOI22_homework) C++
100 / 100
279 ms 208528 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e6 + 25;
string s; deque <char> a7a;
int cnt;
vector <int> adj[MAXN];
int type[MAXN];
stack <int> cur;
int dp[MAXN][2], sze[MAXN];
void dfs (int pos, int t, int par = -1) {
	if (type[pos] == 3) {
		dp[pos][0] = dp[pos][1] = 1;
		sze[pos] = 1;
		return;
	}
	for (auto j : adj[pos]) dfs(j, 3 - t, pos), sze[pos] += sze[j];
	if (type[pos] == 1) {
		dp[pos][0] = 1e9; dp[pos][1] = 1;
		for (auto j : adj[pos]) {
			dp[pos][0] = min(dp[pos][0], dp[j][0]);
			dp[pos][1] += dp[j][1] - 1;
		}
	} else {
		for (auto j : adj[pos]) {
			dp[pos][0] += dp[j][0];
			dp[pos][1] = max(dp[pos][1], sze[pos] - sze[j] + dp[j][1]);
		}
	}
	//cout << pos << ": " << t << " " << dp[pos][0] << " " << dp[pos][1] << '\n';
}
int main () {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> s; 
	for (auto i : s) a7a.push_back(i); 
	int n = 0;
	while (!a7a.empty()) {
		if (a7a.front() == ',' || a7a.front() == '(') {
			a7a.pop_front(); continue;
		}
		if (a7a.front() == ')') {
			a7a.pop_front(); cur.pop(); continue;
		}
		if (a7a[0] == 'm' && a7a[1] == 'i' && a7a[2] == 'n') {
			if (!cur.empty()) {
				if (type[cur.top()] != 1) {
					++cnt; 
					adj[cur.top()].push_back(cnt);
					cur.push(cnt); 
					type[cnt] = 1;
				} else {
					cur.push(cur.top());
				}
			} else {
				++cnt; 
				cur.push(cnt); 
				type[cnt] = 1;
			}
			a7a.pop_front(); a7a.pop_front(); a7a.pop_front();
			continue;
		}
		if (a7a[0] == 'm' && a7a[1] == 'a' && a7a[2] == 'x') {
			if (!cur.empty()) {
				if (type[cur.top()] != 2) {
					++cnt; 
					adj[cur.top()].push_back(cnt);
					cur.push(cnt); 
					type[cnt] = 2;
				} else {
					cur.push(cur.top());
				}
			} else {
				++cnt; 
				cur.push(cnt); 
				type[cnt] = 2;
			}
			a7a.pop_front(); a7a.pop_front(); a7a.pop_front();
			continue;
		}
		if (a7a[0] == '?') {
			n++; ++cnt; 
			if (!cur.empty()) {
				adj[cur.top()].push_back(cnt);
			}
			type[cnt] = 3; a7a.pop_front(); continue;
		}
	}
	dfs(1, type[1]);
	cout << dp[1][1] - dp[1][0] + 1 << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 51800 KB Output is correct
2 Correct 14 ms 51892 KB Output is correct
3 Correct 11 ms 51700 KB Output is correct
4 Correct 11 ms 51804 KB Output is correct
5 Correct 11 ms 51800 KB Output is correct
6 Correct 11 ms 51800 KB Output is correct
7 Correct 11 ms 51804 KB Output is correct
8 Correct 13 ms 51892 KB Output is correct
9 Correct 11 ms 51804 KB Output is correct
10 Correct 11 ms 51804 KB Output is correct
11 Correct 11 ms 52056 KB Output is correct
12 Correct 12 ms 51800 KB Output is correct
13 Correct 12 ms 51804 KB Output is correct
14 Correct 12 ms 51804 KB Output is correct
15 Correct 11 ms 51804 KB Output is correct
16 Correct 12 ms 51896 KB Output is correct
17 Correct 11 ms 51804 KB Output is correct
18 Correct 12 ms 51892 KB Output is correct
19 Correct 11 ms 51804 KB Output is correct
20 Correct 12 ms 51800 KB Output is correct
21 Correct 11 ms 51804 KB Output is correct
22 Correct 11 ms 51804 KB Output is correct
23 Correct 11 ms 51804 KB Output is correct
24 Correct 11 ms 51800 KB Output is correct
25 Correct 11 ms 51804 KB Output is correct
26 Correct 11 ms 51896 KB Output is correct
27 Correct 12 ms 51892 KB Output is correct
28 Correct 11 ms 51804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 51800 KB Output is correct
2 Correct 14 ms 51892 KB Output is correct
3 Correct 11 ms 51700 KB Output is correct
4 Correct 11 ms 51804 KB Output is correct
5 Correct 11 ms 51800 KB Output is correct
6 Correct 11 ms 51800 KB Output is correct
7 Correct 11 ms 51804 KB Output is correct
8 Correct 13 ms 51892 KB Output is correct
9 Correct 11 ms 51804 KB Output is correct
10 Correct 11 ms 51804 KB Output is correct
11 Correct 11 ms 52056 KB Output is correct
12 Correct 12 ms 51800 KB Output is correct
13 Correct 12 ms 51804 KB Output is correct
14 Correct 12 ms 51804 KB Output is correct
15 Correct 11 ms 51804 KB Output is correct
16 Correct 12 ms 51896 KB Output is correct
17 Correct 11 ms 51804 KB Output is correct
18 Correct 12 ms 51892 KB Output is correct
19 Correct 11 ms 51804 KB Output is correct
20 Correct 12 ms 51800 KB Output is correct
21 Correct 11 ms 51804 KB Output is correct
22 Correct 11 ms 51804 KB Output is correct
23 Correct 11 ms 51804 KB Output is correct
24 Correct 11 ms 51800 KB Output is correct
25 Correct 11 ms 51804 KB Output is correct
26 Correct 11 ms 51896 KB Output is correct
27 Correct 12 ms 51892 KB Output is correct
28 Correct 11 ms 51804 KB Output is correct
29 Correct 12 ms 51896 KB Output is correct
30 Correct 11 ms 51888 KB Output is correct
31 Correct 11 ms 51808 KB Output is correct
32 Correct 11 ms 51696 KB Output is correct
33 Correct 12 ms 51888 KB Output is correct
34 Correct 13 ms 51804 KB Output is correct
35 Correct 12 ms 51888 KB Output is correct
36 Correct 11 ms 51808 KB Output is correct
37 Correct 12 ms 51804 KB Output is correct
38 Correct 11 ms 51804 KB Output is correct
39 Correct 11 ms 51800 KB Output is correct
40 Correct 13 ms 51700 KB Output is correct
41 Correct 12 ms 51892 KB Output is correct
42 Correct 12 ms 51804 KB Output is correct
43 Correct 11 ms 51800 KB Output is correct
44 Correct 13 ms 51800 KB Output is correct
45 Correct 11 ms 51804 KB Output is correct
46 Correct 11 ms 51804 KB Output is correct
47 Correct 11 ms 52056 KB Output is correct
48 Correct 11 ms 51804 KB Output is correct
49 Correct 12 ms 51804 KB Output is correct
50 Correct 11 ms 51804 KB Output is correct
51 Correct 11 ms 51804 KB Output is correct
52 Correct 11 ms 51804 KB Output is correct
53 Correct 13 ms 51940 KB Output is correct
54 Correct 11 ms 51804 KB Output is correct
55 Correct 11 ms 51800 KB Output is correct
56 Correct 13 ms 52056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 97388 KB Output is correct
2 Correct 99 ms 98076 KB Output is correct
3 Correct 192 ms 152736 KB Output is correct
4 Correct 192 ms 152360 KB Output is correct
5 Correct 141 ms 115184 KB Output is correct
6 Correct 138 ms 113984 KB Output is correct
7 Correct 139 ms 113988 KB Output is correct
8 Correct 137 ms 114216 KB Output is correct
9 Correct 250 ms 208356 KB Output is correct
10 Correct 244 ms 208136 KB Output is correct
11 Correct 230 ms 208292 KB Output is correct
12 Correct 251 ms 208528 KB Output is correct
13 Correct 13 ms 51924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 51800 KB Output is correct
2 Correct 14 ms 51892 KB Output is correct
3 Correct 11 ms 51700 KB Output is correct
4 Correct 11 ms 51804 KB Output is correct
5 Correct 11 ms 51800 KB Output is correct
6 Correct 11 ms 51800 KB Output is correct
7 Correct 11 ms 51804 KB Output is correct
8 Correct 13 ms 51892 KB Output is correct
9 Correct 11 ms 51804 KB Output is correct
10 Correct 11 ms 51804 KB Output is correct
11 Correct 11 ms 52056 KB Output is correct
12 Correct 12 ms 51800 KB Output is correct
13 Correct 12 ms 51804 KB Output is correct
14 Correct 12 ms 51804 KB Output is correct
15 Correct 11 ms 51804 KB Output is correct
16 Correct 12 ms 51896 KB Output is correct
17 Correct 11 ms 51804 KB Output is correct
18 Correct 12 ms 51892 KB Output is correct
19 Correct 11 ms 51804 KB Output is correct
20 Correct 12 ms 51800 KB Output is correct
21 Correct 11 ms 51804 KB Output is correct
22 Correct 11 ms 51804 KB Output is correct
23 Correct 11 ms 51804 KB Output is correct
24 Correct 11 ms 51800 KB Output is correct
25 Correct 11 ms 51804 KB Output is correct
26 Correct 11 ms 51896 KB Output is correct
27 Correct 12 ms 51892 KB Output is correct
28 Correct 11 ms 51804 KB Output is correct
29 Correct 12 ms 51896 KB Output is correct
30 Correct 11 ms 51888 KB Output is correct
31 Correct 11 ms 51808 KB Output is correct
32 Correct 11 ms 51696 KB Output is correct
33 Correct 12 ms 51888 KB Output is correct
34 Correct 13 ms 51804 KB Output is correct
35 Correct 12 ms 51888 KB Output is correct
36 Correct 11 ms 51808 KB Output is correct
37 Correct 12 ms 51804 KB Output is correct
38 Correct 11 ms 51804 KB Output is correct
39 Correct 11 ms 51800 KB Output is correct
40 Correct 13 ms 51700 KB Output is correct
41 Correct 12 ms 51892 KB Output is correct
42 Correct 12 ms 51804 KB Output is correct
43 Correct 11 ms 51800 KB Output is correct
44 Correct 13 ms 51800 KB Output is correct
45 Correct 11 ms 51804 KB Output is correct
46 Correct 11 ms 51804 KB Output is correct
47 Correct 11 ms 52056 KB Output is correct
48 Correct 11 ms 51804 KB Output is correct
49 Correct 12 ms 51804 KB Output is correct
50 Correct 11 ms 51804 KB Output is correct
51 Correct 11 ms 51804 KB Output is correct
52 Correct 11 ms 51804 KB Output is correct
53 Correct 13 ms 51940 KB Output is correct
54 Correct 11 ms 51804 KB Output is correct
55 Correct 11 ms 51800 KB Output is correct
56 Correct 13 ms 52056 KB Output is correct
57 Correct 13 ms 51804 KB Output is correct
58 Correct 11 ms 51804 KB Output is correct
59 Correct 11 ms 51804 KB Output is correct
60 Correct 12 ms 51800 KB Output is correct
61 Correct 11 ms 51960 KB Output is correct
62 Correct 12 ms 51804 KB Output is correct
63 Correct 11 ms 51804 KB Output is correct
64 Correct 11 ms 51804 KB Output is correct
65 Correct 11 ms 51804 KB Output is correct
66 Correct 11 ms 51804 KB Output is correct
67 Correct 11 ms 51928 KB Output is correct
68 Correct 11 ms 51804 KB Output is correct
69 Correct 11 ms 51932 KB Output is correct
70 Correct 12 ms 51896 KB Output is correct
71 Correct 13 ms 51804 KB Output is correct
72 Correct 13 ms 51944 KB Output is correct
73 Correct 12 ms 51968 KB Output is correct
74 Correct 12 ms 52060 KB Output is correct
75 Correct 12 ms 51936 KB Output is correct
76 Correct 11 ms 52148 KB Output is correct
77 Correct 11 ms 51928 KB Output is correct
78 Correct 11 ms 51800 KB Output is correct
79 Correct 12 ms 51804 KB Output is correct
80 Correct 11 ms 51856 KB Output is correct
81 Correct 11 ms 51804 KB Output is correct
82 Correct 11 ms 51984 KB Output is correct
83 Correct 12 ms 51804 KB Output is correct
84 Correct 12 ms 51804 KB Output is correct
85 Correct 11 ms 51716 KB Output is correct
86 Correct 11 ms 51800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 51800 KB Output is correct
2 Correct 14 ms 51892 KB Output is correct
3 Correct 11 ms 51700 KB Output is correct
4 Correct 11 ms 51804 KB Output is correct
5 Correct 11 ms 51800 KB Output is correct
6 Correct 11 ms 51800 KB Output is correct
7 Correct 11 ms 51804 KB Output is correct
8 Correct 13 ms 51892 KB Output is correct
9 Correct 11 ms 51804 KB Output is correct
10 Correct 11 ms 51804 KB Output is correct
11 Correct 11 ms 52056 KB Output is correct
12 Correct 12 ms 51800 KB Output is correct
13 Correct 12 ms 51804 KB Output is correct
14 Correct 12 ms 51804 KB Output is correct
15 Correct 11 ms 51804 KB Output is correct
16 Correct 12 ms 51896 KB Output is correct
17 Correct 11 ms 51804 KB Output is correct
18 Correct 12 ms 51892 KB Output is correct
19 Correct 11 ms 51804 KB Output is correct
20 Correct 12 ms 51800 KB Output is correct
21 Correct 11 ms 51804 KB Output is correct
22 Correct 11 ms 51804 KB Output is correct
23 Correct 11 ms 51804 KB Output is correct
24 Correct 11 ms 51800 KB Output is correct
25 Correct 11 ms 51804 KB Output is correct
26 Correct 11 ms 51896 KB Output is correct
27 Correct 12 ms 51892 KB Output is correct
28 Correct 11 ms 51804 KB Output is correct
29 Correct 12 ms 51896 KB Output is correct
30 Correct 11 ms 51888 KB Output is correct
31 Correct 11 ms 51808 KB Output is correct
32 Correct 11 ms 51696 KB Output is correct
33 Correct 12 ms 51888 KB Output is correct
34 Correct 13 ms 51804 KB Output is correct
35 Correct 12 ms 51888 KB Output is correct
36 Correct 11 ms 51808 KB Output is correct
37 Correct 12 ms 51804 KB Output is correct
38 Correct 11 ms 51804 KB Output is correct
39 Correct 11 ms 51800 KB Output is correct
40 Correct 13 ms 51700 KB Output is correct
41 Correct 12 ms 51892 KB Output is correct
42 Correct 12 ms 51804 KB Output is correct
43 Correct 11 ms 51800 KB Output is correct
44 Correct 13 ms 51800 KB Output is correct
45 Correct 11 ms 51804 KB Output is correct
46 Correct 11 ms 51804 KB Output is correct
47 Correct 11 ms 52056 KB Output is correct
48 Correct 11 ms 51804 KB Output is correct
49 Correct 12 ms 51804 KB Output is correct
50 Correct 11 ms 51804 KB Output is correct
51 Correct 11 ms 51804 KB Output is correct
52 Correct 11 ms 51804 KB Output is correct
53 Correct 13 ms 51940 KB Output is correct
54 Correct 11 ms 51804 KB Output is correct
55 Correct 11 ms 51800 KB Output is correct
56 Correct 13 ms 52056 KB Output is correct
57 Correct 93 ms 97388 KB Output is correct
58 Correct 99 ms 98076 KB Output is correct
59 Correct 192 ms 152736 KB Output is correct
60 Correct 192 ms 152360 KB Output is correct
61 Correct 141 ms 115184 KB Output is correct
62 Correct 138 ms 113984 KB Output is correct
63 Correct 139 ms 113988 KB Output is correct
64 Correct 137 ms 114216 KB Output is correct
65 Correct 250 ms 208356 KB Output is correct
66 Correct 244 ms 208136 KB Output is correct
67 Correct 230 ms 208292 KB Output is correct
68 Correct 251 ms 208528 KB Output is correct
69 Correct 13 ms 51924 KB Output is correct
70 Correct 13 ms 51804 KB Output is correct
71 Correct 11 ms 51804 KB Output is correct
72 Correct 11 ms 51804 KB Output is correct
73 Correct 12 ms 51800 KB Output is correct
74 Correct 11 ms 51960 KB Output is correct
75 Correct 12 ms 51804 KB Output is correct
76 Correct 11 ms 51804 KB Output is correct
77 Correct 11 ms 51804 KB Output is correct
78 Correct 11 ms 51804 KB Output is correct
79 Correct 11 ms 51804 KB Output is correct
80 Correct 11 ms 51928 KB Output is correct
81 Correct 11 ms 51804 KB Output is correct
82 Correct 11 ms 51932 KB Output is correct
83 Correct 12 ms 51896 KB Output is correct
84 Correct 13 ms 51804 KB Output is correct
85 Correct 13 ms 51944 KB Output is correct
86 Correct 12 ms 51968 KB Output is correct
87 Correct 12 ms 52060 KB Output is correct
88 Correct 12 ms 51936 KB Output is correct
89 Correct 11 ms 52148 KB Output is correct
90 Correct 11 ms 51928 KB Output is correct
91 Correct 11 ms 51800 KB Output is correct
92 Correct 12 ms 51804 KB Output is correct
93 Correct 11 ms 51856 KB Output is correct
94 Correct 11 ms 51804 KB Output is correct
95 Correct 11 ms 51984 KB Output is correct
96 Correct 12 ms 51804 KB Output is correct
97 Correct 12 ms 51804 KB Output is correct
98 Correct 11 ms 51716 KB Output is correct
99 Correct 11 ms 51800 KB Output is correct
100 Correct 176 ms 108776 KB Output is correct
101 Correct 172 ms 108828 KB Output is correct
102 Correct 116 ms 96732 KB Output is correct
103 Correct 118 ms 96796 KB Output is correct
104 Correct 185 ms 125272 KB Output is correct
105 Correct 200 ms 121824 KB Output is correct
106 Correct 187 ms 120592 KB Output is correct
107 Correct 138 ms 101168 KB Output is correct
108 Correct 141 ms 101908 KB Output is correct
109 Correct 221 ms 151332 KB Output is correct
110 Correct 171 ms 108532 KB Output is correct
111 Correct 177 ms 107676 KB Output is correct
112 Correct 122 ms 97124 KB Output is correct
113 Correct 140 ms 95912 KB Output is correct
114 Correct 191 ms 124144 KB Output is correct
115 Correct 213 ms 152804 KB Output is correct
116 Correct 202 ms 151312 KB Output is correct
117 Correct 144 ms 114900 KB Output is correct
118 Correct 143 ms 113940 KB Output is correct
119 Correct 279 ms 207884 KB Output is correct
120 Correct 95 ms 97248 KB Output is correct
121 Correct 94 ms 97328 KB Output is correct
122 Correct 186 ms 107868 KB Output is correct
123 Correct 179 ms 108108 KB Output is correct
124 Correct 155 ms 155324 KB Output is correct
125 Correct 164 ms 155516 KB Output is correct
126 Correct 156 ms 156272 KB Output is correct
127 Correct 162 ms 156308 KB Output is correct
128 Correct 92 ms 80912 KB Output is correct
129 Correct 67 ms 76284 KB Output is correct
130 Correct 95 ms 92024 KB Output is correct
131 Correct 12 ms 51892 KB Output is correct