#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = int(1e6) + 1000;
vector<int> ch[N];
vector<int> d[N];
int l[N], r[N];
int x[N];
void solve() {
string s;
cin >> s;
stack<pii> st;
st.push({0, 0});
int w = 1;
int i = 0;
while (i < s.size()) {
if (s[i] == '?') {
ch[st.top().first].push_back(w);
d[st.top().second+1].push_back(w++);
} else if (s[i] == 'm') {
x[w] = s[i+1] == 'a' ? 2 : 1;
ch[st.top().first].push_back(w);
d[st.top().second+1].push_back(w);
st.push({w++, st.top().second+1});
i += 3;
} else if (s[i] == ')') st.pop();
++i;
}
for (int i = 1e6; i > 0; --i) {
for (int u : d[i]) {
if (x[u] == 0) {
l[u] = r[u] = 0;
} else 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]]);
}
}
}
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
Main.cpp: In function 'void solve()':
Main.cpp:23:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | while (i < s.size()) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
52824 KB |
Output is correct |
2 |
Correct |
12 ms |
52828 KB |
Output is correct |
3 |
Correct |
12 ms |
52828 KB |
Output is correct |
4 |
Correct |
12 ms |
52828 KB |
Output is correct |
5 |
Correct |
12 ms |
52884 KB |
Output is correct |
6 |
Correct |
12 ms |
52832 KB |
Output is correct |
7 |
Correct |
12 ms |
52824 KB |
Output is correct |
8 |
Correct |
12 ms |
52892 KB |
Output is correct |
9 |
Correct |
13 ms |
52828 KB |
Output is correct |
10 |
Correct |
12 ms |
52840 KB |
Output is correct |
11 |
Correct |
12 ms |
52824 KB |
Output is correct |
12 |
Correct |
12 ms |
52812 KB |
Output is correct |
13 |
Correct |
12 ms |
52828 KB |
Output is correct |
14 |
Correct |
14 ms |
52824 KB |
Output is correct |
15 |
Correct |
12 ms |
52828 KB |
Output is correct |
16 |
Correct |
12 ms |
52824 KB |
Output is correct |
17 |
Correct |
12 ms |
52828 KB |
Output is correct |
18 |
Correct |
12 ms |
52828 KB |
Output is correct |
19 |
Correct |
13 ms |
52828 KB |
Output is correct |
20 |
Correct |
12 ms |
52844 KB |
Output is correct |
21 |
Correct |
12 ms |
52828 KB |
Output is correct |
22 |
Correct |
12 ms |
52828 KB |
Output is correct |
23 |
Correct |
12 ms |
52824 KB |
Output is correct |
24 |
Correct |
12 ms |
52828 KB |
Output is correct |
25 |
Correct |
12 ms |
52828 KB |
Output is correct |
26 |
Correct |
12 ms |
52824 KB |
Output is correct |
27 |
Correct |
12 ms |
52828 KB |
Output is correct |
28 |
Correct |
12 ms |
53080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
52824 KB |
Output is correct |
2 |
Correct |
12 ms |
52828 KB |
Output is correct |
3 |
Correct |
12 ms |
52828 KB |
Output is correct |
4 |
Correct |
12 ms |
52828 KB |
Output is correct |
5 |
Correct |
12 ms |
52884 KB |
Output is correct |
6 |
Correct |
12 ms |
52832 KB |
Output is correct |
7 |
Correct |
12 ms |
52824 KB |
Output is correct |
8 |
Correct |
12 ms |
52892 KB |
Output is correct |
9 |
Correct |
13 ms |
52828 KB |
Output is correct |
10 |
Correct |
12 ms |
52840 KB |
Output is correct |
11 |
Correct |
12 ms |
52824 KB |
Output is correct |
12 |
Correct |
12 ms |
52812 KB |
Output is correct |
13 |
Correct |
12 ms |
52828 KB |
Output is correct |
14 |
Correct |
14 ms |
52824 KB |
Output is correct |
15 |
Correct |
12 ms |
52828 KB |
Output is correct |
16 |
Correct |
12 ms |
52824 KB |
Output is correct |
17 |
Correct |
12 ms |
52828 KB |
Output is correct |
18 |
Correct |
12 ms |
52828 KB |
Output is correct |
19 |
Correct |
13 ms |
52828 KB |
Output is correct |
20 |
Correct |
12 ms |
52844 KB |
Output is correct |
21 |
Correct |
12 ms |
52828 KB |
Output is correct |
22 |
Correct |
12 ms |
52828 KB |
Output is correct |
23 |
Correct |
12 ms |
52824 KB |
Output is correct |
24 |
Correct |
12 ms |
52828 KB |
Output is correct |
25 |
Correct |
12 ms |
52828 KB |
Output is correct |
26 |
Correct |
12 ms |
52824 KB |
Output is correct |
27 |
Correct |
12 ms |
52828 KB |
Output is correct |
28 |
Correct |
12 ms |
53080 KB |
Output is correct |
29 |
Correct |
12 ms |
52828 KB |
Output is correct |
30 |
Correct |
15 ms |
52828 KB |
Output is correct |
31 |
Correct |
12 ms |
52832 KB |
Output is correct |
32 |
Correct |
13 ms |
52888 KB |
Output is correct |
33 |
Correct |
12 ms |
52888 KB |
Output is correct |
34 |
Correct |
12 ms |
52828 KB |
Output is correct |
35 |
Correct |
12 ms |
52828 KB |
Output is correct |
36 |
Correct |
14 ms |
52892 KB |
Output is correct |
37 |
Correct |
12 ms |
52828 KB |
Output is correct |
38 |
Correct |
12 ms |
52828 KB |
Output is correct |
39 |
Correct |
12 ms |
52828 KB |
Output is correct |
40 |
Correct |
12 ms |
52828 KB |
Output is correct |
41 |
Correct |
13 ms |
52892 KB |
Output is correct |
42 |
Correct |
12 ms |
52828 KB |
Output is correct |
43 |
Correct |
12 ms |
52828 KB |
Output is correct |
44 |
Correct |
12 ms |
52824 KB |
Output is correct |
45 |
Correct |
13 ms |
52828 KB |
Output is correct |
46 |
Correct |
12 ms |
52828 KB |
Output is correct |
47 |
Correct |
13 ms |
52828 KB |
Output is correct |
48 |
Correct |
13 ms |
52692 KB |
Output is correct |
49 |
Correct |
12 ms |
52676 KB |
Output is correct |
50 |
Correct |
13 ms |
52828 KB |
Output is correct |
51 |
Correct |
14 ms |
52696 KB |
Output is correct |
52 |
Correct |
12 ms |
52828 KB |
Output is correct |
53 |
Correct |
12 ms |
52828 KB |
Output is correct |
54 |
Correct |
12 ms |
52828 KB |
Output is correct |
55 |
Correct |
12 ms |
52828 KB |
Output is correct |
56 |
Correct |
13 ms |
52828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
171 ms |
216960 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
52824 KB |
Output is correct |
2 |
Correct |
12 ms |
52828 KB |
Output is correct |
3 |
Correct |
12 ms |
52828 KB |
Output is correct |
4 |
Correct |
12 ms |
52828 KB |
Output is correct |
5 |
Correct |
12 ms |
52884 KB |
Output is correct |
6 |
Correct |
12 ms |
52832 KB |
Output is correct |
7 |
Correct |
12 ms |
52824 KB |
Output is correct |
8 |
Correct |
12 ms |
52892 KB |
Output is correct |
9 |
Correct |
13 ms |
52828 KB |
Output is correct |
10 |
Correct |
12 ms |
52840 KB |
Output is correct |
11 |
Correct |
12 ms |
52824 KB |
Output is correct |
12 |
Correct |
12 ms |
52812 KB |
Output is correct |
13 |
Correct |
12 ms |
52828 KB |
Output is correct |
14 |
Correct |
14 ms |
52824 KB |
Output is correct |
15 |
Correct |
12 ms |
52828 KB |
Output is correct |
16 |
Correct |
12 ms |
52824 KB |
Output is correct |
17 |
Correct |
12 ms |
52828 KB |
Output is correct |
18 |
Correct |
12 ms |
52828 KB |
Output is correct |
19 |
Correct |
13 ms |
52828 KB |
Output is correct |
20 |
Correct |
12 ms |
52844 KB |
Output is correct |
21 |
Correct |
12 ms |
52828 KB |
Output is correct |
22 |
Correct |
12 ms |
52828 KB |
Output is correct |
23 |
Correct |
12 ms |
52824 KB |
Output is correct |
24 |
Correct |
12 ms |
52828 KB |
Output is correct |
25 |
Correct |
12 ms |
52828 KB |
Output is correct |
26 |
Correct |
12 ms |
52824 KB |
Output is correct |
27 |
Correct |
12 ms |
52828 KB |
Output is correct |
28 |
Correct |
12 ms |
53080 KB |
Output is correct |
29 |
Correct |
12 ms |
52828 KB |
Output is correct |
30 |
Correct |
15 ms |
52828 KB |
Output is correct |
31 |
Correct |
12 ms |
52832 KB |
Output is correct |
32 |
Correct |
13 ms |
52888 KB |
Output is correct |
33 |
Correct |
12 ms |
52888 KB |
Output is correct |
34 |
Correct |
12 ms |
52828 KB |
Output is correct |
35 |
Correct |
12 ms |
52828 KB |
Output is correct |
36 |
Correct |
14 ms |
52892 KB |
Output is correct |
37 |
Correct |
12 ms |
52828 KB |
Output is correct |
38 |
Correct |
12 ms |
52828 KB |
Output is correct |
39 |
Correct |
12 ms |
52828 KB |
Output is correct |
40 |
Correct |
12 ms |
52828 KB |
Output is correct |
41 |
Correct |
13 ms |
52892 KB |
Output is correct |
42 |
Correct |
12 ms |
52828 KB |
Output is correct |
43 |
Correct |
12 ms |
52828 KB |
Output is correct |
44 |
Correct |
12 ms |
52824 KB |
Output is correct |
45 |
Correct |
13 ms |
52828 KB |
Output is correct |
46 |
Correct |
12 ms |
52828 KB |
Output is correct |
47 |
Correct |
13 ms |
52828 KB |
Output is correct |
48 |
Correct |
13 ms |
52692 KB |
Output is correct |
49 |
Correct |
12 ms |
52676 KB |
Output is correct |
50 |
Correct |
13 ms |
52828 KB |
Output is correct |
51 |
Correct |
14 ms |
52696 KB |
Output is correct |
52 |
Correct |
12 ms |
52828 KB |
Output is correct |
53 |
Correct |
12 ms |
52828 KB |
Output is correct |
54 |
Correct |
12 ms |
52828 KB |
Output is correct |
55 |
Correct |
12 ms |
52828 KB |
Output is correct |
56 |
Correct |
13 ms |
52828 KB |
Output is correct |
57 |
Correct |
12 ms |
52828 KB |
Output is correct |
58 |
Correct |
12 ms |
52828 KB |
Output is correct |
59 |
Correct |
12 ms |
52828 KB |
Output is correct |
60 |
Correct |
12 ms |
52828 KB |
Output is correct |
61 |
Correct |
12 ms |
52828 KB |
Output is correct |
62 |
Correct |
12 ms |
52828 KB |
Output is correct |
63 |
Correct |
12 ms |
52828 KB |
Output is correct |
64 |
Correct |
12 ms |
52828 KB |
Output is correct |
65 |
Correct |
12 ms |
52828 KB |
Output is correct |
66 |
Correct |
13 ms |
52828 KB |
Output is correct |
67 |
Correct |
12 ms |
52828 KB |
Output is correct |
68 |
Correct |
12 ms |
52828 KB |
Output is correct |
69 |
Correct |
12 ms |
52848 KB |
Output is correct |
70 |
Correct |
14 ms |
52828 KB |
Output is correct |
71 |
Correct |
13 ms |
52824 KB |
Output is correct |
72 |
Correct |
12 ms |
52828 KB |
Output is correct |
73 |
Correct |
12 ms |
52828 KB |
Output is correct |
74 |
Correct |
12 ms |
52876 KB |
Output is correct |
75 |
Correct |
14 ms |
52828 KB |
Output is correct |
76 |
Correct |
13 ms |
52828 KB |
Output is correct |
77 |
Correct |
12 ms |
52828 KB |
Output is correct |
78 |
Correct |
13 ms |
52944 KB |
Output is correct |
79 |
Correct |
12 ms |
52828 KB |
Output is correct |
80 |
Correct |
13 ms |
52936 KB |
Output is correct |
81 |
Correct |
12 ms |
52824 KB |
Output is correct |
82 |
Correct |
12 ms |
52824 KB |
Output is correct |
83 |
Correct |
12 ms |
52828 KB |
Output is correct |
84 |
Correct |
13 ms |
52828 KB |
Output is correct |
85 |
Correct |
12 ms |
52824 KB |
Output is correct |
86 |
Correct |
12 ms |
52828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
52824 KB |
Output is correct |
2 |
Correct |
12 ms |
52828 KB |
Output is correct |
3 |
Correct |
12 ms |
52828 KB |
Output is correct |
4 |
Correct |
12 ms |
52828 KB |
Output is correct |
5 |
Correct |
12 ms |
52884 KB |
Output is correct |
6 |
Correct |
12 ms |
52832 KB |
Output is correct |
7 |
Correct |
12 ms |
52824 KB |
Output is correct |
8 |
Correct |
12 ms |
52892 KB |
Output is correct |
9 |
Correct |
13 ms |
52828 KB |
Output is correct |
10 |
Correct |
12 ms |
52840 KB |
Output is correct |
11 |
Correct |
12 ms |
52824 KB |
Output is correct |
12 |
Correct |
12 ms |
52812 KB |
Output is correct |
13 |
Correct |
12 ms |
52828 KB |
Output is correct |
14 |
Correct |
14 ms |
52824 KB |
Output is correct |
15 |
Correct |
12 ms |
52828 KB |
Output is correct |
16 |
Correct |
12 ms |
52824 KB |
Output is correct |
17 |
Correct |
12 ms |
52828 KB |
Output is correct |
18 |
Correct |
12 ms |
52828 KB |
Output is correct |
19 |
Correct |
13 ms |
52828 KB |
Output is correct |
20 |
Correct |
12 ms |
52844 KB |
Output is correct |
21 |
Correct |
12 ms |
52828 KB |
Output is correct |
22 |
Correct |
12 ms |
52828 KB |
Output is correct |
23 |
Correct |
12 ms |
52824 KB |
Output is correct |
24 |
Correct |
12 ms |
52828 KB |
Output is correct |
25 |
Correct |
12 ms |
52828 KB |
Output is correct |
26 |
Correct |
12 ms |
52824 KB |
Output is correct |
27 |
Correct |
12 ms |
52828 KB |
Output is correct |
28 |
Correct |
12 ms |
53080 KB |
Output is correct |
29 |
Correct |
12 ms |
52828 KB |
Output is correct |
30 |
Correct |
15 ms |
52828 KB |
Output is correct |
31 |
Correct |
12 ms |
52832 KB |
Output is correct |
32 |
Correct |
13 ms |
52888 KB |
Output is correct |
33 |
Correct |
12 ms |
52888 KB |
Output is correct |
34 |
Correct |
12 ms |
52828 KB |
Output is correct |
35 |
Correct |
12 ms |
52828 KB |
Output is correct |
36 |
Correct |
14 ms |
52892 KB |
Output is correct |
37 |
Correct |
12 ms |
52828 KB |
Output is correct |
38 |
Correct |
12 ms |
52828 KB |
Output is correct |
39 |
Correct |
12 ms |
52828 KB |
Output is correct |
40 |
Correct |
12 ms |
52828 KB |
Output is correct |
41 |
Correct |
13 ms |
52892 KB |
Output is correct |
42 |
Correct |
12 ms |
52828 KB |
Output is correct |
43 |
Correct |
12 ms |
52828 KB |
Output is correct |
44 |
Correct |
12 ms |
52824 KB |
Output is correct |
45 |
Correct |
13 ms |
52828 KB |
Output is correct |
46 |
Correct |
12 ms |
52828 KB |
Output is correct |
47 |
Correct |
13 ms |
52828 KB |
Output is correct |
48 |
Correct |
13 ms |
52692 KB |
Output is correct |
49 |
Correct |
12 ms |
52676 KB |
Output is correct |
50 |
Correct |
13 ms |
52828 KB |
Output is correct |
51 |
Correct |
14 ms |
52696 KB |
Output is correct |
52 |
Correct |
12 ms |
52828 KB |
Output is correct |
53 |
Correct |
12 ms |
52828 KB |
Output is correct |
54 |
Correct |
12 ms |
52828 KB |
Output is correct |
55 |
Correct |
12 ms |
52828 KB |
Output is correct |
56 |
Correct |
13 ms |
52828 KB |
Output is correct |
57 |
Runtime error |
171 ms |
216960 KB |
Execution killed with signal 11 |
58 |
Halted |
0 ms |
0 KB |
- |