# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
861236 | 2023-10-15T17:10:05 Z | vgtcross | Homework (CEOI22_homework) | C++17 | 179 ms | 181704 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const int N = int(2e6) + 1000; vector<int> ch[N]; int l[N], r[N]; int x[N]; void dfs(int u) { if (x[u] == 0) { l[u] = r[u] = 0; return; } for (int v : ch[u]) dfs(v); if (x[u] == 1) { l[u] = min(l[ch[u][0]], l[ch[u][1]]); r[u] = r[ch[u][0]] + r[ch[u][1]] + 1; } else { l[u] = l[ch[u][0]] + l[ch[u][1]] + 1; r[u] = min(r[ch[u][0]], r[ch[u][1]]); } } void solve() { string s; cin >> s; stack<int> st; st.push(0); int w = 1; int i = 0; while (i < s.size()) { if (s[i] == '?') ch[st.top()].push_back(w++); else if (s[i] == 'm') { x[w] = s[i+1] == 'a' ? 2 : 1; ch[st.top()].push_back(w); st.push(w++); i += 3; } else if (s[i] == ')') st.pop(); ++i; } dfs(1); int cnt = 0; for (char c : s) cnt += c == '?'; cout << cnt - l[1] - r[1] << '\n'; } int main() { cin.tie(0) -> sync_with_stdio(0); solve(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 52056 KB | Output is correct |
2 | Correct | 10 ms | 52060 KB | Output is correct |
3 | Correct | 11 ms | 52060 KB | Output is correct |
4 | Correct | 11 ms | 52060 KB | Output is correct |
5 | Correct | 11 ms | 52060 KB | Output is correct |
6 | Correct | 10 ms | 52056 KB | Output is correct |
7 | Correct | 11 ms | 52060 KB | Output is correct |
8 | Correct | 10 ms | 52060 KB | Output is correct |
9 | Correct | 11 ms | 52296 KB | Output is correct |
10 | Correct | 11 ms | 52312 KB | Output is correct |
11 | Correct | 11 ms | 52060 KB | Output is correct |
12 | Correct | 11 ms | 52060 KB | Output is correct |
13 | Correct | 11 ms | 52060 KB | Output is correct |
14 | Correct | 10 ms | 52060 KB | Output is correct |
15 | Correct | 10 ms | 52060 KB | Output is correct |
16 | Correct | 11 ms | 52060 KB | Output is correct |
17 | Correct | 11 ms | 52056 KB | Output is correct |
18 | Correct | 11 ms | 52060 KB | Output is correct |
19 | Correct | 11 ms | 52056 KB | Output is correct |
20 | Correct | 12 ms | 52216 KB | Output is correct |
21 | Correct | 11 ms | 52056 KB | Output is correct |
22 | Correct | 13 ms | 52288 KB | Output is correct |
23 | Correct | 11 ms | 52056 KB | Output is correct |
24 | Correct | 10 ms | 52060 KB | Output is correct |
25 | Correct | 10 ms | 52304 KB | Output is correct |
26 | Correct | 11 ms | 52300 KB | Output is correct |
27 | Correct | 11 ms | 52316 KB | Output is correct |
28 | Correct | 10 ms | 52312 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 52056 KB | Output is correct |
2 | Correct | 10 ms | 52060 KB | Output is correct |
3 | Correct | 11 ms | 52060 KB | Output is correct |
4 | Correct | 11 ms | 52060 KB | Output is correct |
5 | Correct | 11 ms | 52060 KB | Output is correct |
6 | Correct | 10 ms | 52056 KB | Output is correct |
7 | Correct | 11 ms | 52060 KB | Output is correct |
8 | Correct | 10 ms | 52060 KB | Output is correct |
9 | Correct | 11 ms | 52296 KB | Output is correct |
10 | Correct | 11 ms | 52312 KB | Output is correct |
11 | Correct | 11 ms | 52060 KB | Output is correct |
12 | Correct | 11 ms | 52060 KB | Output is correct |
13 | Correct | 11 ms | 52060 KB | Output is correct |
14 | Correct | 10 ms | 52060 KB | Output is correct |
15 | Correct | 10 ms | 52060 KB | Output is correct |
16 | Correct | 11 ms | 52060 KB | Output is correct |
17 | Correct | 11 ms | 52056 KB | Output is correct |
18 | Correct | 11 ms | 52060 KB | Output is correct |
19 | Correct | 11 ms | 52056 KB | Output is correct |
20 | Correct | 12 ms | 52216 KB | Output is correct |
21 | Correct | 11 ms | 52056 KB | Output is correct |
22 | Correct | 13 ms | 52288 KB | Output is correct |
23 | Correct | 11 ms | 52056 KB | Output is correct |
24 | Correct | 10 ms | 52060 KB | Output is correct |
25 | Correct | 10 ms | 52304 KB | Output is correct |
26 | Correct | 11 ms | 52300 KB | Output is correct |
27 | Correct | 11 ms | 52316 KB | Output is correct |
28 | Correct | 10 ms | 52312 KB | Output is correct |
29 | Correct | 11 ms | 52060 KB | Output is correct |
30 | Correct | 11 ms | 52060 KB | Output is correct |
31 | Correct | 11 ms | 52060 KB | Output is correct |
32 | Correct | 10 ms | 52056 KB | Output is correct |
33 | Correct | 10 ms | 52060 KB | Output is correct |
34 | Correct | 11 ms | 52056 KB | Output is correct |
35 | Correct | 11 ms | 52060 KB | Output is correct |
36 | Correct | 12 ms | 52060 KB | Output is correct |
37 | Correct | 11 ms | 52060 KB | Output is correct |
38 | Correct | 11 ms | 52164 KB | Output is correct |
39 | Correct | 11 ms | 52056 KB | Output is correct |
40 | Correct | 10 ms | 52308 KB | Output is correct |
41 | Correct | 11 ms | 52056 KB | Output is correct |
42 | Correct | 10 ms | 52060 KB | Output is correct |
43 | Correct | 11 ms | 52060 KB | Output is correct |
44 | Correct | 11 ms | 52056 KB | Output is correct |
45 | Correct | 10 ms | 52056 KB | Output is correct |
46 | Correct | 10 ms | 52060 KB | Output is correct |
47 | Correct | 11 ms | 52056 KB | Output is correct |
48 | Correct | 10 ms | 52056 KB | Output is correct |
49 | Correct | 10 ms | 52060 KB | Output is correct |
50 | Correct | 10 ms | 52060 KB | Output is correct |
51 | Correct | 11 ms | 52060 KB | Output is correct |
52 | Correct | 11 ms | 52060 KB | Output is correct |
53 | Correct | 12 ms | 52060 KB | Output is correct |
54 | Correct | 11 ms | 52304 KB | Output is correct |
55 | Correct | 11 ms | 52308 KB | Output is correct |
56 | Correct | 11 ms | 52060 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 168 ms | 181704 KB | Output is correct |
2 | Correct | 176 ms | 179356 KB | Output is correct |
3 | Correct | 175 ms | 180692 KB | Output is correct |
4 | Correct | 179 ms | 179516 KB | Output is correct |
5 | Correct | 171 ms | 180384 KB | Output is correct |
6 | Correct | 172 ms | 179916 KB | Output is correct |
7 | Correct | 166 ms | 180304 KB | Output is correct |
8 | Correct | 172 ms | 179168 KB | Output is correct |
9 | Correct | 178 ms | 179604 KB | Output is correct |
10 | Correct | 177 ms | 179880 KB | Output is correct |
11 | Correct | 172 ms | 180044 KB | Output is correct |
12 | Correct | 172 ms | 180356 KB | Output is correct |
13 | Correct | 11 ms | 52060 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 52056 KB | Output is correct |
2 | Correct | 10 ms | 52060 KB | Output is correct |
3 | Correct | 11 ms | 52060 KB | Output is correct |
4 | Correct | 11 ms | 52060 KB | Output is correct |
5 | Correct | 11 ms | 52060 KB | Output is correct |
6 | Correct | 10 ms | 52056 KB | Output is correct |
7 | Correct | 11 ms | 52060 KB | Output is correct |
8 | Correct | 10 ms | 52060 KB | Output is correct |
9 | Correct | 11 ms | 52296 KB | Output is correct |
10 | Correct | 11 ms | 52312 KB | Output is correct |
11 | Correct | 11 ms | 52060 KB | Output is correct |
12 | Correct | 11 ms | 52060 KB | Output is correct |
13 | Correct | 11 ms | 52060 KB | Output is correct |
14 | Correct | 10 ms | 52060 KB | Output is correct |
15 | Correct | 10 ms | 52060 KB | Output is correct |
16 | Correct | 11 ms | 52060 KB | Output is correct |
17 | Correct | 11 ms | 52056 KB | Output is correct |
18 | Correct | 11 ms | 52060 KB | Output is correct |
19 | Correct | 11 ms | 52056 KB | Output is correct |
20 | Correct | 12 ms | 52216 KB | Output is correct |
21 | Correct | 11 ms | 52056 KB | Output is correct |
22 | Correct | 13 ms | 52288 KB | Output is correct |
23 | Correct | 11 ms | 52056 KB | Output is correct |
24 | Correct | 10 ms | 52060 KB | Output is correct |
25 | Correct | 10 ms | 52304 KB | Output is correct |
26 | Correct | 11 ms | 52300 KB | Output is correct |
27 | Correct | 11 ms | 52316 KB | Output is correct |
28 | Correct | 10 ms | 52312 KB | Output is correct |
29 | Correct | 11 ms | 52060 KB | Output is correct |
30 | Correct | 11 ms | 52060 KB | Output is correct |
31 | Correct | 11 ms | 52060 KB | Output is correct |
32 | Correct | 10 ms | 52056 KB | Output is correct |
33 | Correct | 10 ms | 52060 KB | Output is correct |
34 | Correct | 11 ms | 52056 KB | Output is correct |
35 | Correct | 11 ms | 52060 KB | Output is correct |
36 | Correct | 12 ms | 52060 KB | Output is correct |
37 | Correct | 11 ms | 52060 KB | Output is correct |
38 | Correct | 11 ms | 52164 KB | Output is correct |
39 | Correct | 11 ms | 52056 KB | Output is correct |
40 | Correct | 10 ms | 52308 KB | Output is correct |
41 | Correct | 11 ms | 52056 KB | Output is correct |
42 | Correct | 10 ms | 52060 KB | Output is correct |
43 | Correct | 11 ms | 52060 KB | Output is correct |
44 | Correct | 11 ms | 52056 KB | Output is correct |
45 | Correct | 10 ms | 52056 KB | Output is correct |
46 | Correct | 10 ms | 52060 KB | Output is correct |
47 | Correct | 11 ms | 52056 KB | Output is correct |
48 | Correct | 10 ms | 52056 KB | Output is correct |
49 | Correct | 10 ms | 52060 KB | Output is correct |
50 | Correct | 10 ms | 52060 KB | Output is correct |
51 | Correct | 11 ms | 52060 KB | Output is correct |
52 | Correct | 11 ms | 52060 KB | Output is correct |
53 | Correct | 12 ms | 52060 KB | Output is correct |
54 | Correct | 11 ms | 52304 KB | Output is correct |
55 | Correct | 11 ms | 52308 KB | Output is correct |
56 | Correct | 11 ms | 52060 KB | Output is correct |
57 | Correct | 11 ms | 52316 KB | Output is correct |
58 | Correct | 11 ms | 52364 KB | Output is correct |
59 | Correct | 11 ms | 52316 KB | Output is correct |
60 | Correct | 11 ms | 52156 KB | Output is correct |
61 | Correct | 11 ms | 52156 KB | Output is correct |
62 | Correct | 11 ms | 52316 KB | Output is correct |
63 | Correct | 10 ms | 52312 KB | Output is correct |
64 | Correct | 10 ms | 52316 KB | Output is correct |
65 | Correct | 10 ms | 52216 KB | Output is correct |
66 | Correct | 11 ms | 52316 KB | Output is correct |
67 | Correct | 11 ms | 52316 KB | Output is correct |
68 | Correct | 11 ms | 52316 KB | Output is correct |
69 | Correct | 11 ms | 52316 KB | Output is correct |
70 | Correct | 11 ms | 52148 KB | Output is correct |
71 | Correct | 11 ms | 52312 KB | Output is correct |
72 | Correct | 11 ms | 52412 KB | Output is correct |
73 | Correct | 11 ms | 52316 KB | Output is correct |
74 | Correct | 11 ms | 52420 KB | Output is correct |
75 | Correct | 12 ms | 52316 KB | Output is correct |
76 | Correct | 11 ms | 52316 KB | Output is correct |
77 | Correct | 11 ms | 52364 KB | Output is correct |
78 | Correct | 11 ms | 52316 KB | Output is correct |
79 | Correct | 11 ms | 52316 KB | Output is correct |
80 | Correct | 11 ms | 52360 KB | Output is correct |
81 | Correct | 11 ms | 52316 KB | Output is correct |
82 | Correct | 11 ms | 52316 KB | Output is correct |
83 | Correct | 11 ms | 52316 KB | Output is correct |
84 | Correct | 11 ms | 52332 KB | Output is correct |
85 | Correct | 11 ms | 52200 KB | Output is correct |
86 | Correct | 12 ms | 52316 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 52056 KB | Output is correct |
2 | Correct | 10 ms | 52060 KB | Output is correct |
3 | Correct | 11 ms | 52060 KB | Output is correct |
4 | Correct | 11 ms | 52060 KB | Output is correct |
5 | Correct | 11 ms | 52060 KB | Output is correct |
6 | Correct | 10 ms | 52056 KB | Output is correct |
7 | Correct | 11 ms | 52060 KB | Output is correct |
8 | Correct | 10 ms | 52060 KB | Output is correct |
9 | Correct | 11 ms | 52296 KB | Output is correct |
10 | Correct | 11 ms | 52312 KB | Output is correct |
11 | Correct | 11 ms | 52060 KB | Output is correct |
12 | Correct | 11 ms | 52060 KB | Output is correct |
13 | Correct | 11 ms | 52060 KB | Output is correct |
14 | Correct | 10 ms | 52060 KB | Output is correct |
15 | Correct | 10 ms | 52060 KB | Output is correct |
16 | Correct | 11 ms | 52060 KB | Output is correct |
17 | Correct | 11 ms | 52056 KB | Output is correct |
18 | Correct | 11 ms | 52060 KB | Output is correct |
19 | Correct | 11 ms | 52056 KB | Output is correct |
20 | Correct | 12 ms | 52216 KB | Output is correct |
21 | Correct | 11 ms | 52056 KB | Output is correct |
22 | Correct | 13 ms | 52288 KB | Output is correct |
23 | Correct | 11 ms | 52056 KB | Output is correct |
24 | Correct | 10 ms | 52060 KB | Output is correct |
25 | Correct | 10 ms | 52304 KB | Output is correct |
26 | Correct | 11 ms | 52300 KB | Output is correct |
27 | Correct | 11 ms | 52316 KB | Output is correct |
28 | Correct | 10 ms | 52312 KB | Output is correct |
29 | Correct | 11 ms | 52060 KB | Output is correct |
30 | Correct | 11 ms | 52060 KB | Output is correct |
31 | Correct | 11 ms | 52060 KB | Output is correct |
32 | Correct | 10 ms | 52056 KB | Output is correct |
33 | Correct | 10 ms | 52060 KB | Output is correct |
34 | Correct | 11 ms | 52056 KB | Output is correct |
35 | Correct | 11 ms | 52060 KB | Output is correct |
36 | Correct | 12 ms | 52060 KB | Output is correct |
37 | Correct | 11 ms | 52060 KB | Output is correct |
38 | Correct | 11 ms | 52164 KB | Output is correct |
39 | Correct | 11 ms | 52056 KB | Output is correct |
40 | Correct | 10 ms | 52308 KB | Output is correct |
41 | Correct | 11 ms | 52056 KB | Output is correct |
42 | Correct | 10 ms | 52060 KB | Output is correct |
43 | Correct | 11 ms | 52060 KB | Output is correct |
44 | Correct | 11 ms | 52056 KB | Output is correct |
45 | Correct | 10 ms | 52056 KB | Output is correct |
46 | Correct | 10 ms | 52060 KB | Output is correct |
47 | Correct | 11 ms | 52056 KB | Output is correct |
48 | Correct | 10 ms | 52056 KB | Output is correct |
49 | Correct | 10 ms | 52060 KB | Output is correct |
50 | Correct | 10 ms | 52060 KB | Output is correct |
51 | Correct | 11 ms | 52060 KB | Output is correct |
52 | Correct | 11 ms | 52060 KB | Output is correct |
53 | Correct | 12 ms | 52060 KB | Output is correct |
54 | Correct | 11 ms | 52304 KB | Output is correct |
55 | Correct | 11 ms | 52308 KB | Output is correct |
56 | Correct | 11 ms | 52060 KB | Output is correct |
57 | Correct | 168 ms | 181704 KB | Output is correct |
58 | Correct | 176 ms | 179356 KB | Output is correct |
59 | Correct | 175 ms | 180692 KB | Output is correct |
60 | Correct | 179 ms | 179516 KB | Output is correct |
61 | Correct | 171 ms | 180384 KB | Output is correct |
62 | Correct | 172 ms | 179916 KB | Output is correct |
63 | Correct | 166 ms | 180304 KB | Output is correct |
64 | Correct | 172 ms | 179168 KB | Output is correct |
65 | Correct | 178 ms | 179604 KB | Output is correct |
66 | Correct | 177 ms | 179880 KB | Output is correct |
67 | Correct | 172 ms | 180044 KB | Output is correct |
68 | Correct | 172 ms | 180356 KB | Output is correct |
69 | Correct | 11 ms | 52060 KB | Output is correct |
70 | Correct | 11 ms | 52316 KB | Output is correct |
71 | Correct | 11 ms | 52364 KB | Output is correct |
72 | Correct | 11 ms | 52316 KB | Output is correct |
73 | Correct | 11 ms | 52156 KB | Output is correct |
74 | Correct | 11 ms | 52156 KB | Output is correct |
75 | Correct | 11 ms | 52316 KB | Output is correct |
76 | Correct | 10 ms | 52312 KB | Output is correct |
77 | Correct | 10 ms | 52316 KB | Output is correct |
78 | Correct | 10 ms | 52216 KB | Output is correct |
79 | Correct | 11 ms | 52316 KB | Output is correct |
80 | Correct | 11 ms | 52316 KB | Output is correct |
81 | Correct | 11 ms | 52316 KB | Output is correct |
82 | Correct | 11 ms | 52316 KB | Output is correct |
83 | Correct | 11 ms | 52148 KB | Output is correct |
84 | Correct | 11 ms | 52312 KB | Output is correct |
85 | Correct | 11 ms | 52412 KB | Output is correct |
86 | Correct | 11 ms | 52316 KB | Output is correct |
87 | Correct | 11 ms | 52420 KB | Output is correct |
88 | Correct | 12 ms | 52316 KB | Output is correct |
89 | Correct | 11 ms | 52316 KB | Output is correct |
90 | Correct | 11 ms | 52364 KB | Output is correct |
91 | Correct | 11 ms | 52316 KB | Output is correct |
92 | Correct | 11 ms | 52316 KB | Output is correct |
93 | Correct | 11 ms | 52360 KB | Output is correct |
94 | Correct | 11 ms | 52316 KB | Output is correct |
95 | Correct | 11 ms | 52316 KB | Output is correct |
96 | Correct | 11 ms | 52316 KB | Output is correct |
97 | Correct | 11 ms | 52332 KB | Output is correct |
98 | Correct | 11 ms | 52200 KB | Output is correct |
99 | Correct | 12 ms | 52316 KB | Output is correct |
100 | Correct | 125 ms | 113356 KB | Output is correct |
101 | Correct | 124 ms | 113360 KB | Output is correct |
102 | Correct | 120 ms | 112556 KB | Output is correct |
103 | Correct | 129 ms | 112776 KB | Output is correct |
104 | Correct | 119 ms | 113508 KB | Output is correct |
105 | Correct | 149 ms | 133684 KB | Output is correct |
106 | Correct | 151 ms | 134092 KB | Output is correct |
107 | Correct | 164 ms | 133432 KB | Output is correct |
108 | Correct | 145 ms | 133840 KB | Output is correct |
109 | Correct | 147 ms | 133580 KB | Output is correct |
110 | Correct | 134 ms | 113208 KB | Output is correct |
111 | Correct | 131 ms | 113360 KB | Output is correct |
112 | Correct | 129 ms | 112552 KB | Output is correct |
113 | Correct | 130 ms | 113612 KB | Output is correct |
114 | Correct | 126 ms | 112588 KB | Output is correct |
115 | Correct | 178 ms | 179148 KB | Output is correct |
116 | Correct | 179 ms | 179516 KB | Output is correct |
117 | Correct | 168 ms | 179660 KB | Output is correct |
118 | Correct | 171 ms | 180528 KB | Output is correct |
119 | Correct | 171 ms | 176468 KB | Output is correct |
120 | Correct | 132 ms | 110008 KB | Output is correct |
121 | Correct | 124 ms | 109008 KB | Output is correct |
122 | Correct | 129 ms | 109008 KB | Output is correct |
123 | Correct | 133 ms | 110292 KB | Output is correct |
124 | Correct | 140 ms | 142852 KB | Output is correct |
125 | Correct | 137 ms | 142288 KB | Output is correct |
126 | Correct | 140 ms | 143052 KB | Output is correct |
127 | Correct | 135 ms | 143628 KB | Output is correct |
128 | Correct | 63 ms | 84696 KB | Output is correct |
129 | Correct | 61 ms | 84692 KB | Output is correct |
130 | Correct | 74 ms | 84576 KB | Output is correct |
131 | Correct | 11 ms | 52060 KB | Output is correct |