답안 #942294

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
942294 2024-03-10T12:06:51 Z Ghetto Homework (CEOI22_homework) C++17
100 / 100
511 ms 325104 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
int n_nodes;
int l_child[4 * MAX_N], r_child[4 * MAX_N];
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);
    l_child[u] = ++n_nodes; r_child[u] = ++n_nodes;
    build(l_child[u], l + 4, i - 1, d + 1);
    build(r_child[u], 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);
    }
    
    n_nodes = 1;
    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(l_child[u]), r_bounds = find_bounds(r_child[u]);
    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: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++) n += (bool) (str[i] == '?');
      |                     ~~^~~~~~~~~~~~
Main.cpp:30:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for (int i = 0; i < str.size(); i++) {
      |                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 194132 KB Output is correct
2 Correct 40 ms 193884 KB Output is correct
3 Correct 39 ms 193984 KB Output is correct
4 Correct 40 ms 194040 KB Output is correct
5 Correct 39 ms 193872 KB Output is correct
6 Correct 39 ms 193788 KB Output is correct
7 Correct 38 ms 193984 KB Output is correct
8 Correct 39 ms 193876 KB Output is correct
9 Correct 41 ms 193872 KB Output is correct
10 Correct 43 ms 193828 KB Output is correct
11 Correct 39 ms 193884 KB Output is correct
12 Correct 40 ms 193884 KB Output is correct
13 Correct 40 ms 194032 KB Output is correct
14 Correct 41 ms 193876 KB Output is correct
15 Correct 44 ms 193880 KB Output is correct
16 Correct 38 ms 193880 KB Output is correct
17 Correct 39 ms 193884 KB Output is correct
18 Correct 39 ms 193876 KB Output is correct
19 Correct 39 ms 193936 KB Output is correct
20 Correct 38 ms 193972 KB Output is correct
21 Correct 42 ms 193976 KB Output is correct
22 Correct 42 ms 193820 KB Output is correct
23 Correct 39 ms 193872 KB Output is correct
24 Correct 38 ms 193872 KB Output is correct
25 Correct 38 ms 193992 KB Output is correct
26 Correct 38 ms 193980 KB Output is correct
27 Correct 38 ms 193884 KB Output is correct
28 Correct 39 ms 193876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 194132 KB Output is correct
2 Correct 40 ms 193884 KB Output is correct
3 Correct 39 ms 193984 KB Output is correct
4 Correct 40 ms 194040 KB Output is correct
5 Correct 39 ms 193872 KB Output is correct
6 Correct 39 ms 193788 KB Output is correct
7 Correct 38 ms 193984 KB Output is correct
8 Correct 39 ms 193876 KB Output is correct
9 Correct 41 ms 193872 KB Output is correct
10 Correct 43 ms 193828 KB Output is correct
11 Correct 39 ms 193884 KB Output is correct
12 Correct 40 ms 193884 KB Output is correct
13 Correct 40 ms 194032 KB Output is correct
14 Correct 41 ms 193876 KB Output is correct
15 Correct 44 ms 193880 KB Output is correct
16 Correct 38 ms 193880 KB Output is correct
17 Correct 39 ms 193884 KB Output is correct
18 Correct 39 ms 193876 KB Output is correct
19 Correct 39 ms 193936 KB Output is correct
20 Correct 38 ms 193972 KB Output is correct
21 Correct 42 ms 193976 KB Output is correct
22 Correct 42 ms 193820 KB Output is correct
23 Correct 39 ms 193872 KB Output is correct
24 Correct 38 ms 193872 KB Output is correct
25 Correct 38 ms 193992 KB Output is correct
26 Correct 38 ms 193980 KB Output is correct
27 Correct 38 ms 193884 KB Output is correct
28 Correct 39 ms 193876 KB Output is correct
29 Correct 40 ms 193876 KB Output is correct
30 Correct 38 ms 193872 KB Output is correct
31 Correct 41 ms 193872 KB Output is correct
32 Correct 39 ms 194020 KB Output is correct
33 Correct 39 ms 194040 KB Output is correct
34 Correct 40 ms 194132 KB Output is correct
35 Correct 39 ms 194128 KB Output is correct
36 Correct 39 ms 194036 KB Output is correct
37 Correct 44 ms 194040 KB Output is correct
38 Correct 41 ms 194044 KB Output is correct
39 Correct 39 ms 193884 KB Output is correct
40 Correct 40 ms 193884 KB Output is correct
41 Correct 42 ms 194132 KB Output is correct
42 Correct 40 ms 193872 KB Output is correct
43 Correct 40 ms 194040 KB Output is correct
44 Correct 40 ms 193836 KB Output is correct
45 Correct 38 ms 193840 KB Output is correct
46 Correct 43 ms 193876 KB Output is correct
47 Correct 39 ms 193872 KB Output is correct
48 Correct 40 ms 193884 KB Output is correct
49 Correct 44 ms 193872 KB Output is correct
50 Correct 40 ms 193872 KB Output is correct
51 Correct 40 ms 193872 KB Output is correct
52 Correct 39 ms 193884 KB Output is correct
53 Correct 39 ms 194128 KB Output is correct
54 Correct 41 ms 194024 KB Output is correct
55 Correct 43 ms 193872 KB Output is correct
56 Correct 40 ms 193884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 286 ms 317564 KB Output is correct
2 Correct 286 ms 324352 KB Output is correct
3 Correct 287 ms 324272 KB Output is correct
4 Correct 285 ms 324188 KB Output is correct
5 Correct 281 ms 324684 KB Output is correct
6 Correct 308 ms 324304 KB Output is correct
7 Correct 280 ms 324184 KB Output is correct
8 Correct 283 ms 324352 KB Output is correct
9 Correct 280 ms 324904 KB Output is correct
10 Correct 284 ms 324792 KB Output is correct
11 Correct 288 ms 325104 KB Output is correct
12 Correct 287 ms 324276 KB Output is correct
13 Correct 40 ms 194060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 194132 KB Output is correct
2 Correct 40 ms 193884 KB Output is correct
3 Correct 39 ms 193984 KB Output is correct
4 Correct 40 ms 194040 KB Output is correct
5 Correct 39 ms 193872 KB Output is correct
6 Correct 39 ms 193788 KB Output is correct
7 Correct 38 ms 193984 KB Output is correct
8 Correct 39 ms 193876 KB Output is correct
9 Correct 41 ms 193872 KB Output is correct
10 Correct 43 ms 193828 KB Output is correct
11 Correct 39 ms 193884 KB Output is correct
12 Correct 40 ms 193884 KB Output is correct
13 Correct 40 ms 194032 KB Output is correct
14 Correct 41 ms 193876 KB Output is correct
15 Correct 44 ms 193880 KB Output is correct
16 Correct 38 ms 193880 KB Output is correct
17 Correct 39 ms 193884 KB Output is correct
18 Correct 39 ms 193876 KB Output is correct
19 Correct 39 ms 193936 KB Output is correct
20 Correct 38 ms 193972 KB Output is correct
21 Correct 42 ms 193976 KB Output is correct
22 Correct 42 ms 193820 KB Output is correct
23 Correct 39 ms 193872 KB Output is correct
24 Correct 38 ms 193872 KB Output is correct
25 Correct 38 ms 193992 KB Output is correct
26 Correct 38 ms 193980 KB Output is correct
27 Correct 38 ms 193884 KB Output is correct
28 Correct 39 ms 193876 KB Output is correct
29 Correct 40 ms 193876 KB Output is correct
30 Correct 38 ms 193872 KB Output is correct
31 Correct 41 ms 193872 KB Output is correct
32 Correct 39 ms 194020 KB Output is correct
33 Correct 39 ms 194040 KB Output is correct
34 Correct 40 ms 194132 KB Output is correct
35 Correct 39 ms 194128 KB Output is correct
36 Correct 39 ms 194036 KB Output is correct
37 Correct 44 ms 194040 KB Output is correct
38 Correct 41 ms 194044 KB Output is correct
39 Correct 39 ms 193884 KB Output is correct
40 Correct 40 ms 193884 KB Output is correct
41 Correct 42 ms 194132 KB Output is correct
42 Correct 40 ms 193872 KB Output is correct
43 Correct 40 ms 194040 KB Output is correct
44 Correct 40 ms 193836 KB Output is correct
45 Correct 38 ms 193840 KB Output is correct
46 Correct 43 ms 193876 KB Output is correct
47 Correct 39 ms 193872 KB Output is correct
48 Correct 40 ms 193884 KB Output is correct
49 Correct 44 ms 193872 KB Output is correct
50 Correct 40 ms 193872 KB Output is correct
51 Correct 40 ms 193872 KB Output is correct
52 Correct 39 ms 193884 KB Output is correct
53 Correct 39 ms 194128 KB Output is correct
54 Correct 41 ms 194024 KB Output is correct
55 Correct 43 ms 193872 KB Output is correct
56 Correct 40 ms 193884 KB Output is correct
57 Correct 40 ms 193876 KB Output is correct
58 Correct 45 ms 194148 KB Output is correct
59 Correct 41 ms 193884 KB Output is correct
60 Correct 39 ms 194024 KB Output is correct
61 Correct 41 ms 193876 KB Output is correct
62 Correct 39 ms 193876 KB Output is correct
63 Correct 42 ms 194116 KB Output is correct
64 Correct 39 ms 194116 KB Output is correct
65 Correct 39 ms 194124 KB Output is correct
66 Correct 39 ms 194140 KB Output is correct
67 Correct 39 ms 193876 KB Output is correct
68 Correct 42 ms 194084 KB Output is correct
69 Correct 42 ms 193880 KB Output is correct
70 Correct 39 ms 193872 KB Output is correct
71 Correct 39 ms 193876 KB Output is correct
72 Correct 40 ms 194148 KB Output is correct
73 Correct 40 ms 194128 KB Output is correct
74 Correct 39 ms 194072 KB Output is correct
75 Correct 39 ms 194028 KB Output is correct
76 Correct 40 ms 194128 KB Output is correct
77 Correct 41 ms 193872 KB Output is correct
78 Correct 39 ms 193876 KB Output is correct
79 Correct 43 ms 194076 KB Output is correct
80 Correct 44 ms 194248 KB Output is correct
81 Correct 39 ms 194032 KB Output is correct
82 Correct 38 ms 194140 KB Output is correct
83 Correct 38 ms 193884 KB Output is correct
84 Correct 39 ms 193876 KB Output is correct
85 Correct 42 ms 194128 KB Output is correct
86 Correct 39 ms 194004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 194132 KB Output is correct
2 Correct 40 ms 193884 KB Output is correct
3 Correct 39 ms 193984 KB Output is correct
4 Correct 40 ms 194040 KB Output is correct
5 Correct 39 ms 193872 KB Output is correct
6 Correct 39 ms 193788 KB Output is correct
7 Correct 38 ms 193984 KB Output is correct
8 Correct 39 ms 193876 KB Output is correct
9 Correct 41 ms 193872 KB Output is correct
10 Correct 43 ms 193828 KB Output is correct
11 Correct 39 ms 193884 KB Output is correct
12 Correct 40 ms 193884 KB Output is correct
13 Correct 40 ms 194032 KB Output is correct
14 Correct 41 ms 193876 KB Output is correct
15 Correct 44 ms 193880 KB Output is correct
16 Correct 38 ms 193880 KB Output is correct
17 Correct 39 ms 193884 KB Output is correct
18 Correct 39 ms 193876 KB Output is correct
19 Correct 39 ms 193936 KB Output is correct
20 Correct 38 ms 193972 KB Output is correct
21 Correct 42 ms 193976 KB Output is correct
22 Correct 42 ms 193820 KB Output is correct
23 Correct 39 ms 193872 KB Output is correct
24 Correct 38 ms 193872 KB Output is correct
25 Correct 38 ms 193992 KB Output is correct
26 Correct 38 ms 193980 KB Output is correct
27 Correct 38 ms 193884 KB Output is correct
28 Correct 39 ms 193876 KB Output is correct
29 Correct 40 ms 193876 KB Output is correct
30 Correct 38 ms 193872 KB Output is correct
31 Correct 41 ms 193872 KB Output is correct
32 Correct 39 ms 194020 KB Output is correct
33 Correct 39 ms 194040 KB Output is correct
34 Correct 40 ms 194132 KB Output is correct
35 Correct 39 ms 194128 KB Output is correct
36 Correct 39 ms 194036 KB Output is correct
37 Correct 44 ms 194040 KB Output is correct
38 Correct 41 ms 194044 KB Output is correct
39 Correct 39 ms 193884 KB Output is correct
40 Correct 40 ms 193884 KB Output is correct
41 Correct 42 ms 194132 KB Output is correct
42 Correct 40 ms 193872 KB Output is correct
43 Correct 40 ms 194040 KB Output is correct
44 Correct 40 ms 193836 KB Output is correct
45 Correct 38 ms 193840 KB Output is correct
46 Correct 43 ms 193876 KB Output is correct
47 Correct 39 ms 193872 KB Output is correct
48 Correct 40 ms 193884 KB Output is correct
49 Correct 44 ms 193872 KB Output is correct
50 Correct 40 ms 193872 KB Output is correct
51 Correct 40 ms 193872 KB Output is correct
52 Correct 39 ms 193884 KB Output is correct
53 Correct 39 ms 194128 KB Output is correct
54 Correct 41 ms 194024 KB Output is correct
55 Correct 43 ms 193872 KB Output is correct
56 Correct 40 ms 193884 KB Output is correct
57 Correct 286 ms 317564 KB Output is correct
58 Correct 286 ms 324352 KB Output is correct
59 Correct 287 ms 324272 KB Output is correct
60 Correct 285 ms 324188 KB Output is correct
61 Correct 281 ms 324684 KB Output is correct
62 Correct 308 ms 324304 KB Output is correct
63 Correct 280 ms 324184 KB Output is correct
64 Correct 283 ms 324352 KB Output is correct
65 Correct 280 ms 324904 KB Output is correct
66 Correct 284 ms 324792 KB Output is correct
67 Correct 288 ms 325104 KB Output is correct
68 Correct 287 ms 324276 KB Output is correct
69 Correct 40 ms 194060 KB Output is correct
70 Correct 40 ms 193876 KB Output is correct
71 Correct 45 ms 194148 KB Output is correct
72 Correct 41 ms 193884 KB Output is correct
73 Correct 39 ms 194024 KB Output is correct
74 Correct 41 ms 193876 KB Output is correct
75 Correct 39 ms 193876 KB Output is correct
76 Correct 42 ms 194116 KB Output is correct
77 Correct 39 ms 194116 KB Output is correct
78 Correct 39 ms 194124 KB Output is correct
79 Correct 39 ms 194140 KB Output is correct
80 Correct 39 ms 193876 KB Output is correct
81 Correct 42 ms 194084 KB Output is correct
82 Correct 42 ms 193880 KB Output is correct
83 Correct 39 ms 193872 KB Output is correct
84 Correct 39 ms 193876 KB Output is correct
85 Correct 40 ms 194148 KB Output is correct
86 Correct 40 ms 194128 KB Output is correct
87 Correct 39 ms 194072 KB Output is correct
88 Correct 39 ms 194028 KB Output is correct
89 Correct 40 ms 194128 KB Output is correct
90 Correct 41 ms 193872 KB Output is correct
91 Correct 39 ms 193876 KB Output is correct
92 Correct 43 ms 194076 KB Output is correct
93 Correct 44 ms 194248 KB Output is correct
94 Correct 39 ms 194032 KB Output is correct
95 Correct 38 ms 194140 KB Output is correct
96 Correct 38 ms 193884 KB Output is correct
97 Correct 39 ms 193876 KB Output is correct
98 Correct 42 ms 194128 KB Output is correct
99 Correct 39 ms 194004 KB Output is correct
100 Correct 499 ms 277836 KB Output is correct
101 Correct 503 ms 277372 KB Output is correct
102 Correct 491 ms 277376 KB Output is correct
103 Correct 487 ms 277704 KB Output is correct
104 Correct 489 ms 278208 KB Output is correct
105 Correct 277 ms 293824 KB Output is correct
106 Correct 276 ms 292876 KB Output is correct
107 Correct 275 ms 293072 KB Output is correct
108 Correct 269 ms 293044 KB Output is correct
109 Correct 268 ms 293096 KB Output is correct
110 Correct 500 ms 277932 KB Output is correct
111 Correct 511 ms 277412 KB Output is correct
112 Correct 493 ms 277688 KB Output is correct
113 Correct 495 ms 277328 KB Output is correct
114 Correct 491 ms 277432 KB Output is correct
115 Correct 283 ms 324276 KB Output is correct
116 Correct 279 ms 324404 KB Output is correct
117 Correct 322 ms 324232 KB Output is correct
118 Correct 280 ms 324532 KB Output is correct
119 Correct 278 ms 324272 KB Output is correct
120 Correct 490 ms 277412 KB Output is correct
121 Correct 505 ms 277584 KB Output is correct
122 Correct 499 ms 277224 KB Output is correct
123 Correct 488 ms 277944 KB Output is correct
124 Correct 348 ms 301216 KB Output is correct
125 Correct 356 ms 300992 KB Output is correct
126 Correct 351 ms 300880 KB Output is correct
127 Correct 334 ms 300720 KB Output is correct
128 Correct 267 ms 238332 KB Output is correct
129 Correct 268 ms 238176 KB Output is correct
130 Correct 261 ms 238268 KB Output is correct
131 Correct 38 ms 194036 KB Output is correct