답안 #942245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
942245 2024-03-10T11:38:18 Z Ghetto Homework (CEOI22_homework) C++17
23 / 100
403 ms 496860 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int MAX_N = 1e6 + 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++) {
      |                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 189264 KB Output is correct
2 Correct 39 ms 189272 KB Output is correct
3 Correct 37 ms 189276 KB Output is correct
4 Correct 38 ms 189268 KB Output is correct
5 Correct 37 ms 189276 KB Output is correct
6 Correct 39 ms 189264 KB Output is correct
7 Correct 37 ms 189268 KB Output is correct
8 Correct 38 ms 189276 KB Output is correct
9 Correct 37 ms 189272 KB Output is correct
10 Correct 39 ms 189352 KB Output is correct
11 Correct 38 ms 189268 KB Output is correct
12 Correct 38 ms 189276 KB Output is correct
13 Correct 38 ms 189276 KB Output is correct
14 Correct 38 ms 189264 KB Output is correct
15 Correct 39 ms 189264 KB Output is correct
16 Correct 47 ms 189264 KB Output is correct
17 Correct 39 ms 189276 KB Output is correct
18 Correct 38 ms 189276 KB Output is correct
19 Correct 37 ms 189288 KB Output is correct
20 Correct 42 ms 189168 KB Output is correct
21 Correct 44 ms 189340 KB Output is correct
22 Correct 38 ms 189404 KB Output is correct
23 Correct 37 ms 189264 KB Output is correct
24 Correct 40 ms 189364 KB Output is correct
25 Correct 39 ms 189268 KB Output is correct
26 Correct 37 ms 189160 KB Output is correct
27 Correct 38 ms 189268 KB Output is correct
28 Correct 39 ms 189264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 189264 KB Output is correct
2 Correct 39 ms 189272 KB Output is correct
3 Correct 37 ms 189276 KB Output is correct
4 Correct 38 ms 189268 KB Output is correct
5 Correct 37 ms 189276 KB Output is correct
6 Correct 39 ms 189264 KB Output is correct
7 Correct 37 ms 189268 KB Output is correct
8 Correct 38 ms 189276 KB Output is correct
9 Correct 37 ms 189272 KB Output is correct
10 Correct 39 ms 189352 KB Output is correct
11 Correct 38 ms 189268 KB Output is correct
12 Correct 38 ms 189276 KB Output is correct
13 Correct 38 ms 189276 KB Output is correct
14 Correct 38 ms 189264 KB Output is correct
15 Correct 39 ms 189264 KB Output is correct
16 Correct 47 ms 189264 KB Output is correct
17 Correct 39 ms 189276 KB Output is correct
18 Correct 38 ms 189276 KB Output is correct
19 Correct 37 ms 189288 KB Output is correct
20 Correct 42 ms 189168 KB Output is correct
21 Correct 44 ms 189340 KB Output is correct
22 Correct 38 ms 189404 KB Output is correct
23 Correct 37 ms 189264 KB Output is correct
24 Correct 40 ms 189364 KB Output is correct
25 Correct 39 ms 189268 KB Output is correct
26 Correct 37 ms 189160 KB Output is correct
27 Correct 38 ms 189268 KB Output is correct
28 Correct 39 ms 189264 KB Output is correct
29 Correct 37 ms 189264 KB Output is correct
30 Correct 39 ms 189244 KB Output is correct
31 Correct 37 ms 189196 KB Output is correct
32 Correct 39 ms 189180 KB Output is correct
33 Correct 41 ms 189780 KB Output is correct
34 Correct 37 ms 189268 KB Output is correct
35 Correct 37 ms 189272 KB Output is correct
36 Correct 37 ms 189276 KB Output is correct
37 Correct 39 ms 189264 KB Output is correct
38 Correct 40 ms 189400 KB Output is correct
39 Correct 40 ms 189424 KB Output is correct
40 Correct 37 ms 189264 KB Output is correct
41 Correct 38 ms 189268 KB Output is correct
42 Correct 38 ms 189268 KB Output is correct
43 Correct 43 ms 189264 KB Output is correct
44 Correct 40 ms 191568 KB Output is correct
45 Correct 37 ms 189268 KB Output is correct
46 Correct 39 ms 189272 KB Output is correct
47 Correct 38 ms 189380 KB Output is correct
48 Correct 38 ms 191288 KB Output is correct
49 Correct 37 ms 189324 KB Output is correct
50 Correct 37 ms 189368 KB Output is correct
51 Correct 39 ms 189276 KB Output is correct
52 Correct 38 ms 189228 KB Output is correct
53 Correct 42 ms 189272 KB Output is correct
54 Correct 38 ms 189520 KB Output is correct
55 Correct 38 ms 189276 KB Output is correct
56 Correct 38 ms 189268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 403 ms 496860 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 189264 KB Output is correct
2 Correct 39 ms 189272 KB Output is correct
3 Correct 37 ms 189276 KB Output is correct
4 Correct 38 ms 189268 KB Output is correct
5 Correct 37 ms 189276 KB Output is correct
6 Correct 39 ms 189264 KB Output is correct
7 Correct 37 ms 189268 KB Output is correct
8 Correct 38 ms 189276 KB Output is correct
9 Correct 37 ms 189272 KB Output is correct
10 Correct 39 ms 189352 KB Output is correct
11 Correct 38 ms 189268 KB Output is correct
12 Correct 38 ms 189276 KB Output is correct
13 Correct 38 ms 189276 KB Output is correct
14 Correct 38 ms 189264 KB Output is correct
15 Correct 39 ms 189264 KB Output is correct
16 Correct 47 ms 189264 KB Output is correct
17 Correct 39 ms 189276 KB Output is correct
18 Correct 38 ms 189276 KB Output is correct
19 Correct 37 ms 189288 KB Output is correct
20 Correct 42 ms 189168 KB Output is correct
21 Correct 44 ms 189340 KB Output is correct
22 Correct 38 ms 189404 KB Output is correct
23 Correct 37 ms 189264 KB Output is correct
24 Correct 40 ms 189364 KB Output is correct
25 Correct 39 ms 189268 KB Output is correct
26 Correct 37 ms 189160 KB Output is correct
27 Correct 38 ms 189268 KB Output is correct
28 Correct 39 ms 189264 KB Output is correct
29 Correct 37 ms 189264 KB Output is correct
30 Correct 39 ms 189244 KB Output is correct
31 Correct 37 ms 189196 KB Output is correct
32 Correct 39 ms 189180 KB Output is correct
33 Correct 41 ms 189780 KB Output is correct
34 Correct 37 ms 189268 KB Output is correct
35 Correct 37 ms 189272 KB Output is correct
36 Correct 37 ms 189276 KB Output is correct
37 Correct 39 ms 189264 KB Output is correct
38 Correct 40 ms 189400 KB Output is correct
39 Correct 40 ms 189424 KB Output is correct
40 Correct 37 ms 189264 KB Output is correct
41 Correct 38 ms 189268 KB Output is correct
42 Correct 38 ms 189268 KB Output is correct
43 Correct 43 ms 189264 KB Output is correct
44 Correct 40 ms 191568 KB Output is correct
45 Correct 37 ms 189268 KB Output is correct
46 Correct 39 ms 189272 KB Output is correct
47 Correct 38 ms 189380 KB Output is correct
48 Correct 38 ms 191288 KB Output is correct
49 Correct 37 ms 189324 KB Output is correct
50 Correct 37 ms 189368 KB Output is correct
51 Correct 39 ms 189276 KB Output is correct
52 Correct 38 ms 189228 KB Output is correct
53 Correct 42 ms 189272 KB Output is correct
54 Correct 38 ms 189520 KB Output is correct
55 Correct 38 ms 189276 KB Output is correct
56 Correct 38 ms 189268 KB Output is correct
57 Correct 39 ms 189264 KB Output is correct
58 Correct 38 ms 189488 KB Output is correct
59 Correct 38 ms 189276 KB Output is correct
60 Correct 41 ms 189352 KB Output is correct
61 Correct 38 ms 189412 KB Output is correct
62 Runtime error 180 ms 396180 KB Execution killed with signal 11
63 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 189264 KB Output is correct
2 Correct 39 ms 189272 KB Output is correct
3 Correct 37 ms 189276 KB Output is correct
4 Correct 38 ms 189268 KB Output is correct
5 Correct 37 ms 189276 KB Output is correct
6 Correct 39 ms 189264 KB Output is correct
7 Correct 37 ms 189268 KB Output is correct
8 Correct 38 ms 189276 KB Output is correct
9 Correct 37 ms 189272 KB Output is correct
10 Correct 39 ms 189352 KB Output is correct
11 Correct 38 ms 189268 KB Output is correct
12 Correct 38 ms 189276 KB Output is correct
13 Correct 38 ms 189276 KB Output is correct
14 Correct 38 ms 189264 KB Output is correct
15 Correct 39 ms 189264 KB Output is correct
16 Correct 47 ms 189264 KB Output is correct
17 Correct 39 ms 189276 KB Output is correct
18 Correct 38 ms 189276 KB Output is correct
19 Correct 37 ms 189288 KB Output is correct
20 Correct 42 ms 189168 KB Output is correct
21 Correct 44 ms 189340 KB Output is correct
22 Correct 38 ms 189404 KB Output is correct
23 Correct 37 ms 189264 KB Output is correct
24 Correct 40 ms 189364 KB Output is correct
25 Correct 39 ms 189268 KB Output is correct
26 Correct 37 ms 189160 KB Output is correct
27 Correct 38 ms 189268 KB Output is correct
28 Correct 39 ms 189264 KB Output is correct
29 Correct 37 ms 189264 KB Output is correct
30 Correct 39 ms 189244 KB Output is correct
31 Correct 37 ms 189196 KB Output is correct
32 Correct 39 ms 189180 KB Output is correct
33 Correct 41 ms 189780 KB Output is correct
34 Correct 37 ms 189268 KB Output is correct
35 Correct 37 ms 189272 KB Output is correct
36 Correct 37 ms 189276 KB Output is correct
37 Correct 39 ms 189264 KB Output is correct
38 Correct 40 ms 189400 KB Output is correct
39 Correct 40 ms 189424 KB Output is correct
40 Correct 37 ms 189264 KB Output is correct
41 Correct 38 ms 189268 KB Output is correct
42 Correct 38 ms 189268 KB Output is correct
43 Correct 43 ms 189264 KB Output is correct
44 Correct 40 ms 191568 KB Output is correct
45 Correct 37 ms 189268 KB Output is correct
46 Correct 39 ms 189272 KB Output is correct
47 Correct 38 ms 189380 KB Output is correct
48 Correct 38 ms 191288 KB Output is correct
49 Correct 37 ms 189324 KB Output is correct
50 Correct 37 ms 189368 KB Output is correct
51 Correct 39 ms 189276 KB Output is correct
52 Correct 38 ms 189228 KB Output is correct
53 Correct 42 ms 189272 KB Output is correct
54 Correct 38 ms 189520 KB Output is correct
55 Correct 38 ms 189276 KB Output is correct
56 Correct 38 ms 189268 KB Output is correct
57 Runtime error 403 ms 496860 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -