Submission #861218

# Submission time Handle Problem Language Result Execution time Memory
861218 2023-10-15T16:46:46 Z vgtcross Homework (CEOI22_homework) C++17
53 / 100
96 ms 128208 KB
#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];
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

Main.cpp: In function 'void solve()':
Main.cpp:38:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     while (i < s.size()) {
      |            ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29272 KB Output is correct
2 Correct 7 ms 29276 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 5 ms 29272 KB Output is correct
5 Correct 5 ms 29384 KB Output is correct
6 Correct 5 ms 29276 KB Output is correct
7 Correct 6 ms 29388 KB Output is correct
8 Correct 6 ms 29276 KB Output is correct
9 Correct 7 ms 29276 KB Output is correct
10 Correct 6 ms 29272 KB Output is correct
11 Correct 5 ms 29276 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 6 ms 29276 KB Output is correct
15 Correct 5 ms 29276 KB Output is correct
16 Correct 6 ms 29140 KB Output is correct
17 Correct 6 ms 29384 KB Output is correct
18 Correct 6 ms 29392 KB Output is correct
19 Correct 6 ms 29152 KB Output is correct
20 Correct 6 ms 29276 KB Output is correct
21 Correct 6 ms 29276 KB Output is correct
22 Correct 5 ms 29208 KB Output is correct
23 Correct 6 ms 29276 KB Output is correct
24 Correct 6 ms 29276 KB Output is correct
25 Correct 6 ms 29276 KB Output is correct
26 Correct 6 ms 29276 KB Output is correct
27 Correct 6 ms 29276 KB Output is correct
28 Correct 5 ms 29272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29272 KB Output is correct
2 Correct 7 ms 29276 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 5 ms 29272 KB Output is correct
5 Correct 5 ms 29384 KB Output is correct
6 Correct 5 ms 29276 KB Output is correct
7 Correct 6 ms 29388 KB Output is correct
8 Correct 6 ms 29276 KB Output is correct
9 Correct 7 ms 29276 KB Output is correct
10 Correct 6 ms 29272 KB Output is correct
11 Correct 5 ms 29276 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 6 ms 29276 KB Output is correct
15 Correct 5 ms 29276 KB Output is correct
16 Correct 6 ms 29140 KB Output is correct
17 Correct 6 ms 29384 KB Output is correct
18 Correct 6 ms 29392 KB Output is correct
19 Correct 6 ms 29152 KB Output is correct
20 Correct 6 ms 29276 KB Output is correct
21 Correct 6 ms 29276 KB Output is correct
22 Correct 5 ms 29208 KB Output is correct
23 Correct 6 ms 29276 KB Output is correct
24 Correct 6 ms 29276 KB Output is correct
25 Correct 6 ms 29276 KB Output is correct
26 Correct 6 ms 29276 KB Output is correct
27 Correct 6 ms 29276 KB Output is correct
28 Correct 5 ms 29272 KB Output is correct
29 Correct 6 ms 29272 KB Output is correct
30 Correct 6 ms 29276 KB Output is correct
31 Correct 6 ms 29276 KB Output is correct
32 Correct 6 ms 29276 KB Output is correct
33 Correct 6 ms 29276 KB Output is correct
34 Correct 6 ms 29276 KB Output is correct
35 Correct 6 ms 29276 KB Output is correct
36 Correct 6 ms 29272 KB Output is correct
37 Correct 6 ms 29476 KB Output is correct
38 Correct 6 ms 29396 KB Output is correct
39 Correct 6 ms 29276 KB Output is correct
40 Correct 6 ms 29276 KB Output is correct
41 Correct 6 ms 29528 KB Output is correct
42 Correct 5 ms 29276 KB Output is correct
43 Correct 6 ms 29276 KB Output is correct
44 Correct 6 ms 29276 KB Output is correct
45 Correct 5 ms 29272 KB Output is correct
46 Correct 6 ms 29276 KB Output is correct
47 Correct 6 ms 29276 KB Output is correct
48 Correct 5 ms 29276 KB Output is correct
49 Correct 6 ms 29392 KB Output is correct
50 Correct 6 ms 29276 KB Output is correct
51 Correct 6 ms 29276 KB Output is correct
52 Correct 6 ms 29272 KB Output is correct
53 Correct 6 ms 29528 KB Output is correct
54 Correct 6 ms 29388 KB Output is correct
55 Correct 6 ms 29276 KB Output is correct
56 Correct 6 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 96 ms 128208 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29272 KB Output is correct
2 Correct 7 ms 29276 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 5 ms 29272 KB Output is correct
5 Correct 5 ms 29384 KB Output is correct
6 Correct 5 ms 29276 KB Output is correct
7 Correct 6 ms 29388 KB Output is correct
8 Correct 6 ms 29276 KB Output is correct
9 Correct 7 ms 29276 KB Output is correct
10 Correct 6 ms 29272 KB Output is correct
11 Correct 5 ms 29276 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 6 ms 29276 KB Output is correct
15 Correct 5 ms 29276 KB Output is correct
16 Correct 6 ms 29140 KB Output is correct
17 Correct 6 ms 29384 KB Output is correct
18 Correct 6 ms 29392 KB Output is correct
19 Correct 6 ms 29152 KB Output is correct
20 Correct 6 ms 29276 KB Output is correct
21 Correct 6 ms 29276 KB Output is correct
22 Correct 5 ms 29208 KB Output is correct
23 Correct 6 ms 29276 KB Output is correct
24 Correct 6 ms 29276 KB Output is correct
25 Correct 6 ms 29276 KB Output is correct
26 Correct 6 ms 29276 KB Output is correct
27 Correct 6 ms 29276 KB Output is correct
28 Correct 5 ms 29272 KB Output is correct
29 Correct 6 ms 29272 KB Output is correct
30 Correct 6 ms 29276 KB Output is correct
31 Correct 6 ms 29276 KB Output is correct
32 Correct 6 ms 29276 KB Output is correct
33 Correct 6 ms 29276 KB Output is correct
34 Correct 6 ms 29276 KB Output is correct
35 Correct 6 ms 29276 KB Output is correct
36 Correct 6 ms 29272 KB Output is correct
37 Correct 6 ms 29476 KB Output is correct
38 Correct 6 ms 29396 KB Output is correct
39 Correct 6 ms 29276 KB Output is correct
40 Correct 6 ms 29276 KB Output is correct
41 Correct 6 ms 29528 KB Output is correct
42 Correct 5 ms 29276 KB Output is correct
43 Correct 6 ms 29276 KB Output is correct
44 Correct 6 ms 29276 KB Output is correct
45 Correct 5 ms 29272 KB Output is correct
46 Correct 6 ms 29276 KB Output is correct
47 Correct 6 ms 29276 KB Output is correct
48 Correct 5 ms 29276 KB Output is correct
49 Correct 6 ms 29392 KB Output is correct
50 Correct 6 ms 29276 KB Output is correct
51 Correct 6 ms 29276 KB Output is correct
52 Correct 6 ms 29272 KB Output is correct
53 Correct 6 ms 29528 KB Output is correct
54 Correct 6 ms 29388 KB Output is correct
55 Correct 6 ms 29276 KB Output is correct
56 Correct 6 ms 29276 KB Output is correct
57 Correct 6 ms 29276 KB Output is correct
58 Correct 6 ms 29276 KB Output is correct
59 Correct 6 ms 29388 KB Output is correct
60 Correct 7 ms 29276 KB Output is correct
61 Correct 6 ms 29276 KB Output is correct
62 Correct 6 ms 29276 KB Output is correct
63 Correct 7 ms 29284 KB Output is correct
64 Correct 6 ms 29384 KB Output is correct
65 Correct 6 ms 29272 KB Output is correct
66 Correct 6 ms 29384 KB Output is correct
67 Correct 6 ms 29276 KB Output is correct
68 Correct 6 ms 29272 KB Output is correct
69 Correct 6 ms 29272 KB Output is correct
70 Correct 6 ms 29276 KB Output is correct
71 Correct 6 ms 29272 KB Output is correct
72 Correct 6 ms 29276 KB Output is correct
73 Correct 6 ms 29276 KB Output is correct
74 Correct 6 ms 29276 KB Output is correct
75 Correct 6 ms 29276 KB Output is correct
76 Correct 6 ms 29276 KB Output is correct
77 Correct 6 ms 29364 KB Output is correct
78 Correct 6 ms 29276 KB Output is correct
79 Correct 6 ms 29276 KB Output is correct
80 Correct 6 ms 29276 KB Output is correct
81 Correct 6 ms 29276 KB Output is correct
82 Correct 6 ms 29440 KB Output is correct
83 Correct 6 ms 29276 KB Output is correct
84 Correct 6 ms 29276 KB Output is correct
85 Correct 6 ms 29276 KB Output is correct
86 Correct 5 ms 29272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29272 KB Output is correct
2 Correct 7 ms 29276 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 5 ms 29272 KB Output is correct
5 Correct 5 ms 29384 KB Output is correct
6 Correct 5 ms 29276 KB Output is correct
7 Correct 6 ms 29388 KB Output is correct
8 Correct 6 ms 29276 KB Output is correct
9 Correct 7 ms 29276 KB Output is correct
10 Correct 6 ms 29272 KB Output is correct
11 Correct 5 ms 29276 KB Output is correct
12 Correct 6 ms 29276 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 6 ms 29276 KB Output is correct
15 Correct 5 ms 29276 KB Output is correct
16 Correct 6 ms 29140 KB Output is correct
17 Correct 6 ms 29384 KB Output is correct
18 Correct 6 ms 29392 KB Output is correct
19 Correct 6 ms 29152 KB Output is correct
20 Correct 6 ms 29276 KB Output is correct
21 Correct 6 ms 29276 KB Output is correct
22 Correct 5 ms 29208 KB Output is correct
23 Correct 6 ms 29276 KB Output is correct
24 Correct 6 ms 29276 KB Output is correct
25 Correct 6 ms 29276 KB Output is correct
26 Correct 6 ms 29276 KB Output is correct
27 Correct 6 ms 29276 KB Output is correct
28 Correct 5 ms 29272 KB Output is correct
29 Correct 6 ms 29272 KB Output is correct
30 Correct 6 ms 29276 KB Output is correct
31 Correct 6 ms 29276 KB Output is correct
32 Correct 6 ms 29276 KB Output is correct
33 Correct 6 ms 29276 KB Output is correct
34 Correct 6 ms 29276 KB Output is correct
35 Correct 6 ms 29276 KB Output is correct
36 Correct 6 ms 29272 KB Output is correct
37 Correct 6 ms 29476 KB Output is correct
38 Correct 6 ms 29396 KB Output is correct
39 Correct 6 ms 29276 KB Output is correct
40 Correct 6 ms 29276 KB Output is correct
41 Correct 6 ms 29528 KB Output is correct
42 Correct 5 ms 29276 KB Output is correct
43 Correct 6 ms 29276 KB Output is correct
44 Correct 6 ms 29276 KB Output is correct
45 Correct 5 ms 29272 KB Output is correct
46 Correct 6 ms 29276 KB Output is correct
47 Correct 6 ms 29276 KB Output is correct
48 Correct 5 ms 29276 KB Output is correct
49 Correct 6 ms 29392 KB Output is correct
50 Correct 6 ms 29276 KB Output is correct
51 Correct 6 ms 29276 KB Output is correct
52 Correct 6 ms 29272 KB Output is correct
53 Correct 6 ms 29528 KB Output is correct
54 Correct 6 ms 29388 KB Output is correct
55 Correct 6 ms 29276 KB Output is correct
56 Correct 6 ms 29276 KB Output is correct
57 Runtime error 96 ms 128208 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -