Submission #861234

# Submission time Handle Problem Language Result Execution time Memory
861234 2023-10-15T17:09:23 Z vgtcross Homework (CEOI22_homework) C++17
100 / 100
256 ms 200372 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];
vector<int> d[N];
int l[N], r[N];
int x[N];

void solve() {
    string s;
    cin >> s;
    
    vector<pii> st;
    st.push_back({0, 0});
    
    int w = 1;
    int i = 0;
    while (i < s.size()) {
        if (s[i] == '?') {
            ch[st.back().first].push_back(w);
            d[st.back().second+1].push_back(w++);
        } else if (s[i] == 'm') {
            x[w] = s[i+1] == 'a' ? 2 : 1;
            ch[st.back().first].push_back(w);
            d[st.back().second+1].push_back(w);
            st.push_back({w++, st.back().second+1});
            i += 3;
        } else if (s[i] == ')') st.pop_back();
        ++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()) {
      |            ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 26 ms 95064 KB Output is correct
2 Correct 24 ms 95064 KB Output is correct
3 Correct 25 ms 95320 KB Output is correct
4 Correct 25 ms 95064 KB Output is correct
5 Correct 25 ms 95068 KB Output is correct
6 Correct 27 ms 95320 KB Output is correct
7 Correct 24 ms 95064 KB Output is correct
8 Correct 24 ms 95112 KB Output is correct
9 Correct 26 ms 95068 KB Output is correct
10 Correct 24 ms 95068 KB Output is correct
11 Correct 25 ms 95068 KB Output is correct
12 Correct 24 ms 95064 KB Output is correct
13 Correct 25 ms 95068 KB Output is correct
14 Correct 24 ms 95068 KB Output is correct
15 Correct 26 ms 95572 KB Output is correct
16 Correct 25 ms 95064 KB Output is correct
17 Correct 26 ms 95000 KB Output is correct
18 Correct 25 ms 95064 KB Output is correct
19 Correct 25 ms 94968 KB Output is correct
20 Correct 25 ms 95068 KB Output is correct
21 Correct 25 ms 95068 KB Output is correct
22 Correct 24 ms 95068 KB Output is correct
23 Correct 24 ms 95204 KB Output is correct
24 Correct 24 ms 95068 KB Output is correct
25 Correct 24 ms 95068 KB Output is correct
26 Correct 25 ms 95068 KB Output is correct
27 Correct 26 ms 95068 KB Output is correct
28 Correct 26 ms 95064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 95064 KB Output is correct
2 Correct 24 ms 95064 KB Output is correct
3 Correct 25 ms 95320 KB Output is correct
4 Correct 25 ms 95064 KB Output is correct
5 Correct 25 ms 95068 KB Output is correct
6 Correct 27 ms 95320 KB Output is correct
7 Correct 24 ms 95064 KB Output is correct
8 Correct 24 ms 95112 KB Output is correct
9 Correct 26 ms 95068 KB Output is correct
10 Correct 24 ms 95068 KB Output is correct
11 Correct 25 ms 95068 KB Output is correct
12 Correct 24 ms 95064 KB Output is correct
13 Correct 25 ms 95068 KB Output is correct
14 Correct 24 ms 95068 KB Output is correct
15 Correct 26 ms 95572 KB Output is correct
16 Correct 25 ms 95064 KB Output is correct
17 Correct 26 ms 95000 KB Output is correct
18 Correct 25 ms 95064 KB Output is correct
19 Correct 25 ms 94968 KB Output is correct
20 Correct 25 ms 95068 KB Output is correct
21 Correct 25 ms 95068 KB Output is correct
22 Correct 24 ms 95068 KB Output is correct
23 Correct 24 ms 95204 KB Output is correct
24 Correct 24 ms 95068 KB Output is correct
25 Correct 24 ms 95068 KB Output is correct
26 Correct 25 ms 95068 KB Output is correct
27 Correct 26 ms 95068 KB Output is correct
28 Correct 26 ms 95064 KB Output is correct
29 Correct 26 ms 95068 KB Output is correct
30 Correct 25 ms 95064 KB Output is correct
31 Correct 29 ms 95068 KB Output is correct
32 Correct 26 ms 95064 KB Output is correct
33 Correct 31 ms 95568 KB Output is correct
34 Correct 29 ms 95064 KB Output is correct
35 Correct 27 ms 95068 KB Output is correct
36 Correct 25 ms 95068 KB Output is correct
37 Correct 26 ms 95068 KB Output is correct
38 Correct 26 ms 95064 KB Output is correct
39 Correct 25 ms 95064 KB Output is correct
40 Correct 25 ms 95068 KB Output is correct
41 Correct 25 ms 94988 KB Output is correct
42 Correct 29 ms 95068 KB Output is correct
43 Correct 26 ms 95064 KB Output is correct
44 Correct 25 ms 95064 KB Output is correct
45 Correct 27 ms 95064 KB Output is correct
46 Correct 27 ms 95144 KB Output is correct
47 Correct 26 ms 95064 KB Output is correct
48 Correct 26 ms 95068 KB Output is correct
49 Correct 25 ms 95068 KB Output is correct
50 Correct 25 ms 95064 KB Output is correct
51 Correct 28 ms 95204 KB Output is correct
52 Correct 25 ms 95068 KB Output is correct
53 Correct 26 ms 95068 KB Output is correct
54 Correct 26 ms 95164 KB Output is correct
55 Correct 25 ms 95068 KB Output is correct
56 Correct 25 ms 95068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 244 ms 193084 KB Output is correct
2 Correct 228 ms 199984 KB Output is correct
3 Correct 207 ms 200124 KB Output is correct
4 Correct 228 ms 199988 KB Output is correct
5 Correct 225 ms 200012 KB Output is correct
6 Correct 207 ms 199908 KB Output is correct
7 Correct 209 ms 200372 KB Output is correct
8 Correct 208 ms 199960 KB Output is correct
9 Correct 201 ms 200064 KB Output is correct
10 Correct 227 ms 200060 KB Output is correct
11 Correct 199 ms 200124 KB Output is correct
12 Correct 200 ms 199984 KB Output is correct
13 Correct 27 ms 94968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 95064 KB Output is correct
2 Correct 24 ms 95064 KB Output is correct
3 Correct 25 ms 95320 KB Output is correct
4 Correct 25 ms 95064 KB Output is correct
5 Correct 25 ms 95068 KB Output is correct
6 Correct 27 ms 95320 KB Output is correct
7 Correct 24 ms 95064 KB Output is correct
8 Correct 24 ms 95112 KB Output is correct
9 Correct 26 ms 95068 KB Output is correct
10 Correct 24 ms 95068 KB Output is correct
11 Correct 25 ms 95068 KB Output is correct
12 Correct 24 ms 95064 KB Output is correct
13 Correct 25 ms 95068 KB Output is correct
14 Correct 24 ms 95068 KB Output is correct
15 Correct 26 ms 95572 KB Output is correct
16 Correct 25 ms 95064 KB Output is correct
17 Correct 26 ms 95000 KB Output is correct
18 Correct 25 ms 95064 KB Output is correct
19 Correct 25 ms 94968 KB Output is correct
20 Correct 25 ms 95068 KB Output is correct
21 Correct 25 ms 95068 KB Output is correct
22 Correct 24 ms 95068 KB Output is correct
23 Correct 24 ms 95204 KB Output is correct
24 Correct 24 ms 95068 KB Output is correct
25 Correct 24 ms 95068 KB Output is correct
26 Correct 25 ms 95068 KB Output is correct
27 Correct 26 ms 95068 KB Output is correct
28 Correct 26 ms 95064 KB Output is correct
29 Correct 26 ms 95068 KB Output is correct
30 Correct 25 ms 95064 KB Output is correct
31 Correct 29 ms 95068 KB Output is correct
32 Correct 26 ms 95064 KB Output is correct
33 Correct 31 ms 95568 KB Output is correct
34 Correct 29 ms 95064 KB Output is correct
35 Correct 27 ms 95068 KB Output is correct
36 Correct 25 ms 95068 KB Output is correct
37 Correct 26 ms 95068 KB Output is correct
38 Correct 26 ms 95064 KB Output is correct
39 Correct 25 ms 95064 KB Output is correct
40 Correct 25 ms 95068 KB Output is correct
41 Correct 25 ms 94988 KB Output is correct
42 Correct 29 ms 95068 KB Output is correct
43 Correct 26 ms 95064 KB Output is correct
44 Correct 25 ms 95064 KB Output is correct
45 Correct 27 ms 95064 KB Output is correct
46 Correct 27 ms 95144 KB Output is correct
47 Correct 26 ms 95064 KB Output is correct
48 Correct 26 ms 95068 KB Output is correct
49 Correct 25 ms 95068 KB Output is correct
50 Correct 25 ms 95064 KB Output is correct
51 Correct 28 ms 95204 KB Output is correct
52 Correct 25 ms 95068 KB Output is correct
53 Correct 26 ms 95068 KB Output is correct
54 Correct 26 ms 95164 KB Output is correct
55 Correct 25 ms 95068 KB Output is correct
56 Correct 25 ms 95068 KB Output is correct
57 Correct 25 ms 95064 KB Output is correct
58 Correct 26 ms 95288 KB Output is correct
59 Correct 26 ms 95128 KB Output is correct
60 Correct 25 ms 95068 KB Output is correct
61 Correct 26 ms 95112 KB Output is correct
62 Correct 28 ms 95156 KB Output is correct
63 Correct 26 ms 95068 KB Output is correct
64 Correct 25 ms 95176 KB Output is correct
65 Correct 27 ms 95064 KB Output is correct
66 Correct 26 ms 95064 KB Output is correct
67 Correct 25 ms 95068 KB Output is correct
68 Correct 26 ms 95068 KB Output is correct
69 Correct 29 ms 95096 KB Output is correct
70 Correct 25 ms 95068 KB Output is correct
71 Correct 25 ms 95288 KB Output is correct
72 Correct 25 ms 95064 KB Output is correct
73 Correct 25 ms 95068 KB Output is correct
74 Correct 25 ms 95064 KB Output is correct
75 Correct 27 ms 95320 KB Output is correct
76 Correct 25 ms 95068 KB Output is correct
77 Correct 26 ms 95068 KB Output is correct
78 Correct 29 ms 95064 KB Output is correct
79 Correct 25 ms 95068 KB Output is correct
80 Correct 25 ms 95264 KB Output is correct
81 Correct 25 ms 95068 KB Output is correct
82 Correct 25 ms 95068 KB Output is correct
83 Correct 29 ms 95324 KB Output is correct
84 Correct 26 ms 95068 KB Output is correct
85 Correct 25 ms 95068 KB Output is correct
86 Correct 26 ms 95068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 95064 KB Output is correct
2 Correct 24 ms 95064 KB Output is correct
3 Correct 25 ms 95320 KB Output is correct
4 Correct 25 ms 95064 KB Output is correct
5 Correct 25 ms 95068 KB Output is correct
6 Correct 27 ms 95320 KB Output is correct
7 Correct 24 ms 95064 KB Output is correct
8 Correct 24 ms 95112 KB Output is correct
9 Correct 26 ms 95068 KB Output is correct
10 Correct 24 ms 95068 KB Output is correct
11 Correct 25 ms 95068 KB Output is correct
12 Correct 24 ms 95064 KB Output is correct
13 Correct 25 ms 95068 KB Output is correct
14 Correct 24 ms 95068 KB Output is correct
15 Correct 26 ms 95572 KB Output is correct
16 Correct 25 ms 95064 KB Output is correct
17 Correct 26 ms 95000 KB Output is correct
18 Correct 25 ms 95064 KB Output is correct
19 Correct 25 ms 94968 KB Output is correct
20 Correct 25 ms 95068 KB Output is correct
21 Correct 25 ms 95068 KB Output is correct
22 Correct 24 ms 95068 KB Output is correct
23 Correct 24 ms 95204 KB Output is correct
24 Correct 24 ms 95068 KB Output is correct
25 Correct 24 ms 95068 KB Output is correct
26 Correct 25 ms 95068 KB Output is correct
27 Correct 26 ms 95068 KB Output is correct
28 Correct 26 ms 95064 KB Output is correct
29 Correct 26 ms 95068 KB Output is correct
30 Correct 25 ms 95064 KB Output is correct
31 Correct 29 ms 95068 KB Output is correct
32 Correct 26 ms 95064 KB Output is correct
33 Correct 31 ms 95568 KB Output is correct
34 Correct 29 ms 95064 KB Output is correct
35 Correct 27 ms 95068 KB Output is correct
36 Correct 25 ms 95068 KB Output is correct
37 Correct 26 ms 95068 KB Output is correct
38 Correct 26 ms 95064 KB Output is correct
39 Correct 25 ms 95064 KB Output is correct
40 Correct 25 ms 95068 KB Output is correct
41 Correct 25 ms 94988 KB Output is correct
42 Correct 29 ms 95068 KB Output is correct
43 Correct 26 ms 95064 KB Output is correct
44 Correct 25 ms 95064 KB Output is correct
45 Correct 27 ms 95064 KB Output is correct
46 Correct 27 ms 95144 KB Output is correct
47 Correct 26 ms 95064 KB Output is correct
48 Correct 26 ms 95068 KB Output is correct
49 Correct 25 ms 95068 KB Output is correct
50 Correct 25 ms 95064 KB Output is correct
51 Correct 28 ms 95204 KB Output is correct
52 Correct 25 ms 95068 KB Output is correct
53 Correct 26 ms 95068 KB Output is correct
54 Correct 26 ms 95164 KB Output is correct
55 Correct 25 ms 95068 KB Output is correct
56 Correct 25 ms 95068 KB Output is correct
57 Correct 244 ms 193084 KB Output is correct
58 Correct 228 ms 199984 KB Output is correct
59 Correct 207 ms 200124 KB Output is correct
60 Correct 228 ms 199988 KB Output is correct
61 Correct 225 ms 200012 KB Output is correct
62 Correct 207 ms 199908 KB Output is correct
63 Correct 209 ms 200372 KB Output is correct
64 Correct 208 ms 199960 KB Output is correct
65 Correct 201 ms 200064 KB Output is correct
66 Correct 227 ms 200060 KB Output is correct
67 Correct 199 ms 200124 KB Output is correct
68 Correct 200 ms 199984 KB Output is correct
69 Correct 27 ms 94968 KB Output is correct
70 Correct 25 ms 95064 KB Output is correct
71 Correct 26 ms 95288 KB Output is correct
72 Correct 26 ms 95128 KB Output is correct
73 Correct 25 ms 95068 KB Output is correct
74 Correct 26 ms 95112 KB Output is correct
75 Correct 28 ms 95156 KB Output is correct
76 Correct 26 ms 95068 KB Output is correct
77 Correct 25 ms 95176 KB Output is correct
78 Correct 27 ms 95064 KB Output is correct
79 Correct 26 ms 95064 KB Output is correct
80 Correct 25 ms 95068 KB Output is correct
81 Correct 26 ms 95068 KB Output is correct
82 Correct 29 ms 95096 KB Output is correct
83 Correct 25 ms 95068 KB Output is correct
84 Correct 25 ms 95288 KB Output is correct
85 Correct 25 ms 95064 KB Output is correct
86 Correct 25 ms 95068 KB Output is correct
87 Correct 25 ms 95064 KB Output is correct
88 Correct 27 ms 95320 KB Output is correct
89 Correct 25 ms 95068 KB Output is correct
90 Correct 26 ms 95068 KB Output is correct
91 Correct 29 ms 95064 KB Output is correct
92 Correct 25 ms 95068 KB Output is correct
93 Correct 25 ms 95264 KB Output is correct
94 Correct 25 ms 95068 KB Output is correct
95 Correct 25 ms 95068 KB Output is correct
96 Correct 29 ms 95324 KB Output is correct
97 Correct 26 ms 95068 KB Output is correct
98 Correct 25 ms 95068 KB Output is correct
99 Correct 26 ms 95068 KB Output is correct
100 Correct 207 ms 170788 KB Output is correct
101 Correct 190 ms 170848 KB Output is correct
102 Correct 184 ms 170608 KB Output is correct
103 Correct 174 ms 170616 KB Output is correct
104 Correct 203 ms 170648 KB Output is correct
105 Correct 207 ms 180036 KB Output is correct
106 Correct 243 ms 180176 KB Output is correct
107 Correct 211 ms 180348 KB Output is correct
108 Correct 209 ms 180168 KB Output is correct
109 Correct 241 ms 180028 KB Output is correct
110 Correct 195 ms 171076 KB Output is correct
111 Correct 194 ms 170700 KB Output is correct
112 Correct 191 ms 171136 KB Output is correct
113 Correct 201 ms 171280 KB Output is correct
114 Correct 216 ms 170804 KB Output is correct
115 Correct 216 ms 200124 KB Output is correct
116 Correct 206 ms 200012 KB Output is correct
117 Correct 214 ms 200092 KB Output is correct
118 Correct 256 ms 200120 KB Output is correct
119 Correct 216 ms 199868 KB Output is correct
120 Correct 206 ms 170956 KB Output is correct
121 Correct 206 ms 172332 KB Output is correct
122 Correct 200 ms 171128 KB Output is correct
123 Correct 207 ms 171816 KB Output is correct
124 Correct 175 ms 187004 KB Output is correct
125 Correct 167 ms 187084 KB Output is correct
126 Correct 184 ms 188204 KB Output is correct
127 Correct 191 ms 186832 KB Output is correct
128 Correct 89 ms 139328 KB Output is correct
129 Correct 86 ms 139308 KB Output is correct
130 Correct 88 ms 139732 KB Output is correct
131 Correct 23 ms 99164 KB Output is correct