Submission #942244

# Submission time Handle Problem Language Result Execution time Memory
942244 2024-03-10T11:37:41 Z Ghetto Homework (CEOI22_homework) C++17
23 / 100
154 ms 82348 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int MAX_N = 1e5 + 5;

string str;
int n;

set<int> commas_at_depth[4 * MAX_N]; // Starts at 1
int type[4 * MAX_N]; // 1 = min, 2 = max, 3 = leaf
void build(int u, int l, int r, int d) {
    // cout << u << " " << l << " " << r << " " << d << endl;
    if (l == r) {
        type[u] = 3;
        return;
    }

    type[u] = (str[l + 1] == 'i') ? 1 : 2;
    int i = *commas_at_depth[d].lower_bound(l);
    build(2 * u, l + 4, i - 1, d + 1);
    build(2 * u + 1, i + 1, r - 1, d + 1);
}
void precomp() {
    for (int i = 0; i < str.size(); i++) n += (bool) (str[i] == '?');

    int depth = 0;
    for (int i = 0; i < str.size(); i++) {
        if (str[i] == '(') depth++;
        else if (str[i] == ')') depth--;
        else if (str[i] == ',') commas_at_depth[depth].insert(i);
    }

    build(1, 0, str.size() - 1, 1);

    // for (int i = 1; i <= 4 * n; i++) {
    //     cout << i << ": " << type[i] << endl;
    // }    
}

pii find_bounds(int u) {
    if (type[u] == 3) return {0, 0};

    pii l_bounds = find_bounds(2 * u), r_bounds = find_bounds(2 * u + 1);
    int min_bound = (type[u] == 1) ? min(l_bounds.first, r_bounds.first) : l_bounds.first + r_bounds.first + 1;
    int max_bound = (type[u] == 1) ? l_bounds.second + r_bounds.second + 1 : min(l_bounds.second, r_bounds.second);
    return {min_bound, max_bound};
}

int main() {
    // freopen("homework.in", "r", stdin);

    cin >> str;
    precomp();

    pii bounds = find_bounds(1);
    int ans = n - bounds.first - bounds.second;
    cout << ans << '\n';
}

Compilation message

Main.cpp: In function 'void precomp()':
Main.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i = 0; i < str.size(); i++) n += (bool) (str[i] == '?');
      |                     ~~^~~~~~~~~~~~
Main.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int i = 0; i < str.size(); i++) {
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 20568 KB Output is correct
2 Correct 5 ms 20572 KB Output is correct
3 Correct 5 ms 20572 KB Output is correct
4 Correct 5 ms 20568 KB Output is correct
5 Correct 5 ms 20572 KB Output is correct
6 Correct 4 ms 20572 KB Output is correct
7 Correct 5 ms 20572 KB Output is correct
8 Correct 5 ms 20572 KB Output is correct
9 Correct 6 ms 20416 KB Output is correct
10 Correct 5 ms 20572 KB Output is correct
11 Correct 5 ms 20616 KB Output is correct
12 Correct 5 ms 20572 KB Output is correct
13 Correct 4 ms 20572 KB Output is correct
14 Correct 4 ms 20568 KB Output is correct
15 Correct 4 ms 20404 KB Output is correct
16 Correct 5 ms 20572 KB Output is correct
17 Correct 5 ms 20572 KB Output is correct
18 Correct 5 ms 20624 KB Output is correct
19 Correct 4 ms 20572 KB Output is correct
20 Correct 4 ms 20408 KB Output is correct
21 Correct 4 ms 20572 KB Output is correct
22 Correct 6 ms 20572 KB Output is correct
23 Correct 5 ms 20572 KB Output is correct
24 Correct 5 ms 20568 KB Output is correct
25 Correct 5 ms 20572 KB Output is correct
26 Correct 5 ms 20628 KB Output is correct
27 Correct 4 ms 20568 KB Output is correct
28 Correct 6 ms 20568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 20568 KB Output is correct
2 Correct 5 ms 20572 KB Output is correct
3 Correct 5 ms 20572 KB Output is correct
4 Correct 5 ms 20568 KB Output is correct
5 Correct 5 ms 20572 KB Output is correct
6 Correct 4 ms 20572 KB Output is correct
7 Correct 5 ms 20572 KB Output is correct
8 Correct 5 ms 20572 KB Output is correct
9 Correct 6 ms 20416 KB Output is correct
10 Correct 5 ms 20572 KB Output is correct
11 Correct 5 ms 20616 KB Output is correct
12 Correct 5 ms 20572 KB Output is correct
13 Correct 4 ms 20572 KB Output is correct
14 Correct 4 ms 20568 KB Output is correct
15 Correct 4 ms 20404 KB Output is correct
16 Correct 5 ms 20572 KB Output is correct
17 Correct 5 ms 20572 KB Output is correct
18 Correct 5 ms 20624 KB Output is correct
19 Correct 4 ms 20572 KB Output is correct
20 Correct 4 ms 20408 KB Output is correct
21 Correct 4 ms 20572 KB Output is correct
22 Correct 6 ms 20572 KB Output is correct
23 Correct 5 ms 20572 KB Output is correct
24 Correct 5 ms 20568 KB Output is correct
25 Correct 5 ms 20572 KB Output is correct
26 Correct 5 ms 20628 KB Output is correct
27 Correct 4 ms 20568 KB Output is correct
28 Correct 6 ms 20568 KB Output is correct
29 Correct 5 ms 20568 KB Output is correct
30 Correct 4 ms 20572 KB Output is correct
31 Correct 4 ms 20572 KB Output is correct
32 Correct 5 ms 20572 KB Output is correct
33 Correct 4 ms 20568 KB Output is correct
34 Correct 4 ms 20572 KB Output is correct
35 Correct 5 ms 20572 KB Output is correct
36 Correct 4 ms 20572 KB Output is correct
37 Correct 4 ms 20572 KB Output is correct
38 Correct 6 ms 20568 KB Output is correct
39 Correct 6 ms 20568 KB Output is correct
40 Correct 4 ms 20568 KB Output is correct
41 Correct 5 ms 20572 KB Output is correct
42 Correct 5 ms 20572 KB Output is correct
43 Correct 4 ms 20572 KB Output is correct
44 Correct 4 ms 20572 KB Output is correct
45 Correct 5 ms 20572 KB Output is correct
46 Correct 4 ms 20568 KB Output is correct
47 Correct 5 ms 20568 KB Output is correct
48 Correct 5 ms 20572 KB Output is correct
49 Correct 5 ms 20620 KB Output is correct
50 Correct 5 ms 20572 KB Output is correct
51 Correct 4 ms 20572 KB Output is correct
52 Correct 6 ms 20572 KB Output is correct
53 Correct 5 ms 20572 KB Output is correct
54 Correct 6 ms 20568 KB Output is correct
55 Correct 4 ms 20572 KB Output is correct
56 Correct 5 ms 20772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 154 ms 82348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 20568 KB Output is correct
2 Correct 5 ms 20572 KB Output is correct
3 Correct 5 ms 20572 KB Output is correct
4 Correct 5 ms 20568 KB Output is correct
5 Correct 5 ms 20572 KB Output is correct
6 Correct 4 ms 20572 KB Output is correct
7 Correct 5 ms 20572 KB Output is correct
8 Correct 5 ms 20572 KB Output is correct
9 Correct 6 ms 20416 KB Output is correct
10 Correct 5 ms 20572 KB Output is correct
11 Correct 5 ms 20616 KB Output is correct
12 Correct 5 ms 20572 KB Output is correct
13 Correct 4 ms 20572 KB Output is correct
14 Correct 4 ms 20568 KB Output is correct
15 Correct 4 ms 20404 KB Output is correct
16 Correct 5 ms 20572 KB Output is correct
17 Correct 5 ms 20572 KB Output is correct
18 Correct 5 ms 20624 KB Output is correct
19 Correct 4 ms 20572 KB Output is correct
20 Correct 4 ms 20408 KB Output is correct
21 Correct 4 ms 20572 KB Output is correct
22 Correct 6 ms 20572 KB Output is correct
23 Correct 5 ms 20572 KB Output is correct
24 Correct 5 ms 20568 KB Output is correct
25 Correct 5 ms 20572 KB Output is correct
26 Correct 5 ms 20628 KB Output is correct
27 Correct 4 ms 20568 KB Output is correct
28 Correct 6 ms 20568 KB Output is correct
29 Correct 5 ms 20568 KB Output is correct
30 Correct 4 ms 20572 KB Output is correct
31 Correct 4 ms 20572 KB Output is correct
32 Correct 5 ms 20572 KB Output is correct
33 Correct 4 ms 20568 KB Output is correct
34 Correct 4 ms 20572 KB Output is correct
35 Correct 5 ms 20572 KB Output is correct
36 Correct 4 ms 20572 KB Output is correct
37 Correct 4 ms 20572 KB Output is correct
38 Correct 6 ms 20568 KB Output is correct
39 Correct 6 ms 20568 KB Output is correct
40 Correct 4 ms 20568 KB Output is correct
41 Correct 5 ms 20572 KB Output is correct
42 Correct 5 ms 20572 KB Output is correct
43 Correct 4 ms 20572 KB Output is correct
44 Correct 4 ms 20572 KB Output is correct
45 Correct 5 ms 20572 KB Output is correct
46 Correct 4 ms 20568 KB Output is correct
47 Correct 5 ms 20568 KB Output is correct
48 Correct 5 ms 20572 KB Output is correct
49 Correct 5 ms 20620 KB Output is correct
50 Correct 5 ms 20572 KB Output is correct
51 Correct 4 ms 20572 KB Output is correct
52 Correct 6 ms 20572 KB Output is correct
53 Correct 5 ms 20572 KB Output is correct
54 Correct 6 ms 20568 KB Output is correct
55 Correct 4 ms 20572 KB Output is correct
56 Correct 5 ms 20772 KB Output is correct
57 Correct 7 ms 20572 KB Output is correct
58 Correct 5 ms 20824 KB Output is correct
59 Correct 5 ms 20572 KB Output is correct
60 Correct 5 ms 20572 KB Output is correct
61 Correct 5 ms 20572 KB Output is correct
62 Runtime error 20 ms 41556 KB Execution killed with signal 11
63 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 20568 KB Output is correct
2 Correct 5 ms 20572 KB Output is correct
3 Correct 5 ms 20572 KB Output is correct
4 Correct 5 ms 20568 KB Output is correct
5 Correct 5 ms 20572 KB Output is correct
6 Correct 4 ms 20572 KB Output is correct
7 Correct 5 ms 20572 KB Output is correct
8 Correct 5 ms 20572 KB Output is correct
9 Correct 6 ms 20416 KB Output is correct
10 Correct 5 ms 20572 KB Output is correct
11 Correct 5 ms 20616 KB Output is correct
12 Correct 5 ms 20572 KB Output is correct
13 Correct 4 ms 20572 KB Output is correct
14 Correct 4 ms 20568 KB Output is correct
15 Correct 4 ms 20404 KB Output is correct
16 Correct 5 ms 20572 KB Output is correct
17 Correct 5 ms 20572 KB Output is correct
18 Correct 5 ms 20624 KB Output is correct
19 Correct 4 ms 20572 KB Output is correct
20 Correct 4 ms 20408 KB Output is correct
21 Correct 4 ms 20572 KB Output is correct
22 Correct 6 ms 20572 KB Output is correct
23 Correct 5 ms 20572 KB Output is correct
24 Correct 5 ms 20568 KB Output is correct
25 Correct 5 ms 20572 KB Output is correct
26 Correct 5 ms 20628 KB Output is correct
27 Correct 4 ms 20568 KB Output is correct
28 Correct 6 ms 20568 KB Output is correct
29 Correct 5 ms 20568 KB Output is correct
30 Correct 4 ms 20572 KB Output is correct
31 Correct 4 ms 20572 KB Output is correct
32 Correct 5 ms 20572 KB Output is correct
33 Correct 4 ms 20568 KB Output is correct
34 Correct 4 ms 20572 KB Output is correct
35 Correct 5 ms 20572 KB Output is correct
36 Correct 4 ms 20572 KB Output is correct
37 Correct 4 ms 20572 KB Output is correct
38 Correct 6 ms 20568 KB Output is correct
39 Correct 6 ms 20568 KB Output is correct
40 Correct 4 ms 20568 KB Output is correct
41 Correct 5 ms 20572 KB Output is correct
42 Correct 5 ms 20572 KB Output is correct
43 Correct 4 ms 20572 KB Output is correct
44 Correct 4 ms 20572 KB Output is correct
45 Correct 5 ms 20572 KB Output is correct
46 Correct 4 ms 20568 KB Output is correct
47 Correct 5 ms 20568 KB Output is correct
48 Correct 5 ms 20572 KB Output is correct
49 Correct 5 ms 20620 KB Output is correct
50 Correct 5 ms 20572 KB Output is correct
51 Correct 4 ms 20572 KB Output is correct
52 Correct 6 ms 20572 KB Output is correct
53 Correct 5 ms 20572 KB Output is correct
54 Correct 6 ms 20568 KB Output is correct
55 Correct 4 ms 20572 KB Output is correct
56 Correct 5 ms 20772 KB Output is correct
57 Runtime error 154 ms 82348 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -