답안 #831762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
831762 2023-08-20T13:44:36 Z QwertyPi Homework (CEOI22_homework) C++14
100 / 100
235 ms 101420 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e6 + 11;
const int INF = 1 << 30;
int L = INF, R = -INF;
int l[MAXN], r[MAXN], t[MAXN];

struct range{
    int x00, x01, x10, x11;
};

range sz[MAXN];
bool ok[MAXN];
bool is_leaf(int v){
    return l[v] == 0 && r[v] == 0;
}

void dfs(int v){
    if(is_leaf(v)){
        sz[v] = {0, 0, 1, 1};
    }else{
        dfs(l[v]); dfs(r[v]);
        if(t[v] == 1){
            sz[v].x00 = sz[l[v]].x00 + sz[r[v]].x00;
            sz[v].x01 = sz[l[v]].x01 + sz[r[v]].x01;
            sz[v].x10 = min(sz[l[v]].x10 + sz[r[v]].x00, sz[l[v]].x00 + sz[r[v]].x10);
            sz[v].x11 = sz[l[v]].x11 + sz[r[v]].x11;
        }else{
            sz[v].x00 = sz[l[v]].x00 + sz[r[v]].x00;
            sz[v].x01 = max(sz[l[v]].x01 + sz[r[v]].x11, sz[l[v]].x11 + sz[r[v]].x01);
            sz[v].x10 = sz[l[v]].x10 + sz[r[v]].x10;
            sz[v].x11 = sz[l[v]].x11 + sz[r[v]].x11;
        }
    }
}

void dfs2(int v, int vl = 0, int vr = 0){
    if(is_leaf(v)){
        L = min(L, vl);
        R = max(R, vr);
    }else{
        if(t[v] == 1){
            dfs2(l[v], vl + sz[r[v]].x00, vr + sz[r[v]].x01);
            dfs2(r[v], vl + sz[l[v]].x00, vr + sz[l[v]].x01);
        }else{
            dfs2(l[v], vl + sz[r[v]].x10, vr + sz[r[v]].x11);
            dfs2(r[v], vl + sz[l[v]].x10, vr + sz[l[v]].x11);
        }
    }
}

int parse_string(string s){
    int id = 0;
    vector<int> v;
    vector<int> op;
    for(int i = 0; i < s.size();){
        if(s[i] == 'm'){
            string t = s.substr(i, 3);
            if(t == "max"){
                op.push_back(1);
                i += 4;
            }else if(t == "min"){
                op.push_back(2);
                i += 4;
            }else{
                assert(0 == 1);
            }
        }else if(s[i] == ')'){
            ++id;
            t[id] = op.back(); l[id] = v[v.size() - 2]; r[id] = v[v.size() - 1];
            op.pop_back(); v.pop_back(); v.pop_back(); v.push_back(id);
            i++;
        }else if(s[i] == ','){
            i++;
        }else if(s[i] == '?'){
            v.push_back(++id);
            i++;
        }
    }
    return id;
}

int32_t main(){
    string s; cin >> s;
    int root = parse_string(s); dfs(root); dfs2(root);
    int ans = R - L + 1;
    cout << ans << endl;
}

Compilation message

Main.cpp: In function 'int parse_string(std::string)':
Main.cpp:58:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for(int i = 0; i < s.size();){
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 304 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 304 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 308 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 312 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 312 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 312 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 1 ms 308 KB Output is correct
50 Correct 0 ms 308 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 0 ms 312 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 1 ms 308 KB Output is correct
56 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 204 ms 91944 KB Output is correct
2 Correct 199 ms 91644 KB Output is correct
3 Correct 211 ms 91832 KB Output is correct
4 Correct 207 ms 92804 KB Output is correct
5 Correct 206 ms 92816 KB Output is correct
6 Correct 201 ms 91500 KB Output is correct
7 Correct 197 ms 94400 KB Output is correct
8 Correct 196 ms 92208 KB Output is correct
9 Correct 196 ms 93028 KB Output is correct
10 Correct 200 ms 91504 KB Output is correct
11 Correct 197 ms 92836 KB Output is correct
12 Correct 203 ms 91608 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 304 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 308 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 312 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 312 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 312 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 1 ms 308 KB Output is correct
50 Correct 0 ms 308 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 0 ms 312 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 1 ms 308 KB Output is correct
56 Correct 0 ms 340 KB Output is correct
57 Correct 1 ms 312 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 340 KB Output is correct
63 Correct 1 ms 340 KB Output is correct
64 Correct 1 ms 340 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Correct 1 ms 304 KB Output is correct
67 Correct 1 ms 312 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 0 ms 308 KB Output is correct
84 Correct 0 ms 340 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 304 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 1 ms 308 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 0 ms 308 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 312 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 312 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 312 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 0 ms 340 KB Output is correct
49 Correct 1 ms 308 KB Output is correct
50 Correct 0 ms 308 KB Output is correct
51 Correct 1 ms 340 KB Output is correct
52 Correct 1 ms 340 KB Output is correct
53 Correct 0 ms 312 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 1 ms 308 KB Output is correct
56 Correct 0 ms 340 KB Output is correct
57 Correct 204 ms 91944 KB Output is correct
58 Correct 199 ms 91644 KB Output is correct
59 Correct 211 ms 91832 KB Output is correct
60 Correct 207 ms 92804 KB Output is correct
61 Correct 206 ms 92816 KB Output is correct
62 Correct 201 ms 91500 KB Output is correct
63 Correct 197 ms 94400 KB Output is correct
64 Correct 196 ms 92208 KB Output is correct
65 Correct 196 ms 93028 KB Output is correct
66 Correct 200 ms 91504 KB Output is correct
67 Correct 197 ms 92836 KB Output is correct
68 Correct 203 ms 91608 KB Output is correct
69 Correct 0 ms 212 KB Output is correct
70 Correct 1 ms 312 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 1 ms 340 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 340 KB Output is correct
79 Correct 1 ms 304 KB Output is correct
80 Correct 1 ms 312 KB Output is correct
81 Correct 1 ms 340 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 1 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 1 ms 340 KB Output is correct
87 Correct 1 ms 340 KB Output is correct
88 Correct 1 ms 340 KB Output is correct
89 Correct 1 ms 340 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 1 ms 340 KB Output is correct
93 Correct 1 ms 340 KB Output is correct
94 Correct 1 ms 340 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 0 ms 308 KB Output is correct
97 Correct 0 ms 340 KB Output is correct
98 Correct 1 ms 340 KB Output is correct
99 Correct 0 ms 340 KB Output is correct
100 Correct 188 ms 68832 KB Output is correct
101 Correct 193 ms 69184 KB Output is correct
102 Correct 180 ms 68824 KB Output is correct
103 Correct 235 ms 68816 KB Output is correct
104 Correct 171 ms 68912 KB Output is correct
105 Correct 194 ms 82552 KB Output is correct
106 Correct 191 ms 83248 KB Output is correct
107 Correct 184 ms 82532 KB Output is correct
108 Correct 179 ms 83196 KB Output is correct
109 Correct 177 ms 83520 KB Output is correct
110 Correct 191 ms 68912 KB Output is correct
111 Correct 197 ms 68912 KB Output is correct
112 Correct 182 ms 68908 KB Output is correct
113 Correct 210 ms 68820 KB Output is correct
114 Correct 181 ms 69000 KB Output is correct
115 Correct 210 ms 101324 KB Output is correct
116 Correct 209 ms 99104 KB Output is correct
117 Correct 205 ms 101420 KB Output is correct
118 Correct 190 ms 100784 KB Output is correct
119 Correct 193 ms 98376 KB Output is correct
120 Correct 185 ms 68908 KB Output is correct
121 Correct 181 ms 68848 KB Output is correct
122 Correct 191 ms 68820 KB Output is correct
123 Correct 191 ms 68904 KB Output is correct
124 Correct 180 ms 83888 KB Output is correct
125 Correct 190 ms 83996 KB Output is correct
126 Correct 173 ms 83880 KB Output is correct
127 Correct 171 ms 83876 KB Output is correct
128 Correct 95 ms 36364 KB Output is correct
129 Correct 90 ms 36284 KB Output is correct
130 Correct 88 ms 36364 KB Output is correct
131 Correct 0 ms 340 KB Output is correct