Submission #830391

# Submission time Handle Problem Language Result Execution time Memory
830391 2023-08-19T05:32:02 Z peteza Homework (CEOI22_homework) C++14
53 / 100
133 ms 46824 KB
#include <bits/stdc++.h>
using namespace std;

string str;
int bin[1000005][2];
int type[1000005], sz[1000005];
int cnode = 0;
stack<int> stk;

int ci = 0;

pair<int, int> dfs(int x) {
    if(type[x] == 2) return {1, 1};
    queue<int> q; q.emplace(x);
    vector<int> dfss;
    while(!q.empty()) {
        if(type[q.front()] == type[x]) {
            q.push(bin[q.front()][0]);
            q.push(bin[q.front()][1]);
        } else dfss.push_back(q.front());
        q.pop();
    }
    int l, r;
    if(type[x] == 0) {
        l = INT_MAX; r = 0;
        for(int e:dfss) {
            pair<int, int> res = dfs(e);
            l = min(res.first, l);
            r += sz[e]-res.second+1;
        }        
        r = sz[x] - r + 1;
    } else {
        l = 0; r = INT_MAX;
        for(int e:dfss) {
            pair<int, int> res = dfs(e);
            l += res.first;
            r = min(sz[e]-res.second, r);
        }
        r = sz[x] - r;
    }
    //cout << x << " -> " << l << ' ' << r << '\n';
    return {l, r};
}


int main() {
    cin >> str; 
    for(int i=0;i<str.size();) {
        if(str[i] == ',' || str[i]=='('){i++; continue;}
        if(str[i] == 'm') {
            stk.push(cnode);
            if(str[i+1] == 'i') { //minimum
                type[cnode++] = 0;
            } else {
                type[cnode++] = 1;
            }
            i += 4;
        } else if(str[i] == '?') {
            stk.push(cnode); sz[cnode] = 1;
            type[cnode++] = 2;
            i++;
        } else {
            int e1 = stk.top(); stk.pop();
            int e2 = stk.top(); stk.pop();
            bin[stk.top()][0] = e2; bin[stk.top()][1] = e1;
            sz[stk.top()] = sz[e1] + sz[e2];
            i++;
        }
    }
    pair<int, int> res = dfs(0);
    cout << res.second - res.first + 1;
}

// min(max(max(?,?),max(?,?)),min(max(?,?),max(?,?)))

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i=0;i<str.size();) {
      |                 ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 312 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 308 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 312 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 308 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 308 KB Output is correct
52 Correct 1 ms 312 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 133 ms 46824 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 312 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 308 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 308 KB Output is correct
52 Correct 1 ms 312 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 1 ms 340 KB Output is correct
58 Correct 1 ms 340 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 0 ms 340 KB Output is correct
61 Correct 1 ms 340 KB Output is correct
62 Correct 1 ms 468 KB Output is correct
63 Correct 1 ms 528 KB Output is correct
64 Correct 0 ms 340 KB Output is correct
65 Correct 0 ms 340 KB Output is correct
66 Correct 1 ms 596 KB Output is correct
67 Correct 0 ms 340 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 0 ms 340 KB Output is correct
71 Correct 1 ms 340 KB Output is correct
72 Correct 1 ms 724 KB Output is correct
73 Correct 1 ms 724 KB Output is correct
74 Correct 1 ms 468 KB Output is correct
75 Correct 1 ms 468 KB Output is correct
76 Correct 1 ms 1108 KB Output is correct
77 Correct 0 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 0 ms 340 KB Output is correct
81 Correct 1 ms 724 KB Output is correct
82 Correct 1 ms 724 KB Output is correct
83 Correct 0 ms 340 KB Output is correct
84 Correct 0 ms 340 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 312 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 312 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 308 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 1 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 212 KB Output is correct
43 Correct 0 ms 212 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 0 ms 340 KB Output is correct
46 Correct 1 ms 212 KB Output is correct
47 Correct 0 ms 212 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 308 KB Output is correct
52 Correct 1 ms 312 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 212 KB Output is correct
55 Correct 1 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Runtime error 133 ms 46824 KB Execution killed with signal 11
58 Halted 0 ms 0 KB -