Submission #1014811

# Submission time Handle Problem Language Result Execution time Memory
1014811 2024-07-05T14:45:52 Z atom Homework (CEOI22_homework) C++17
100 / 100
203 ms 186316 KB
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;

#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif

const int N = 1e6 + 5;

int n, sz;
string s; 
vector <int> c;

struct Node {
    int t;
    Node *l, *r;
};

Node* make(int& i) {
    Node* cur = new Node;
    if (s[i] == '?') {
        ++i;
        cur->t = 0;
        cur->l = cur->r = nullptr;
        return cur;
    }    

    if (s[i + 1] == 'i') {
        cur->t = -1;
    }
    else {
        cur->t = -2;
    }
    i += 4;
    cur->l = make(i);
    ++i;
    cur->r = make(i);
    ++i;

    return cur;
}
using T = array <int, 3>;
// cnt, up, lo;
T solve(Node* tr) {
    if (tr->t == 0) return {1, 1, 1};
    
    T ql = solve(tr->l);
    T qr = solve(tr->r);
    T res;
    res[0] = ql[0] + qr[0];
    if (tr->t == -1) {
        res[1] = min(ql[1], qr[1]);
        res[2] = ql[2] + qr[2] - 1;
    }
    else {
        res[1] = ql[1] + qr[1];
        res[2] = max(ql[2] + qr[0], qr[2] + ql[0]);
    }
    return res;
}


signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    
    #ifdef JASPER
        freopen("in1", "r", stdin);
    #endif

    cin >> s;
    sz = s.size();
    
    int p = 0;
    Node* tr = make(p);
    T ans = solve(tr);
    debug(ans);
    cout << (ans[2] - ans[1] + 1) << "\n";

    // if (n >= 9) {
    //     c.resize(n);
    //     iota(c.begin(), c.end(), 1);

    //     vector <int> vals;
    //     do {
    //         vals.push_back(dfs(tr));
    //     } while (next_permutation(c.begin(), c.end()));

    //     sort(vals.begin(), vals.end());
    //     vals.resize(unique(vals.begin(), vals.end()) - vals.begin());

    //     cout << dfs(tr) << "\n";
    // }
    // else {
    //     debug(n);
    //     T ans = solve(tr);
    //     // debug(ans);
    //     // cout << (ans[2] - ans[1] + 1) << "\n";
    // }

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:9:20: warning: statement has no effect [-Wunused-value]
    9 | #define debug(...) 166
      |                    ^~~
Main.cpp:80:5: note: in expansion of macro 'debug'
   80 |     debug(ans);
      |     ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 460 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 456 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 460 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 456 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 456 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 456 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 344 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 186300 KB Output is correct
2 Correct 176 ms 186140 KB Output is correct
3 Correct 173 ms 186128 KB Output is correct
4 Correct 182 ms 186316 KB Output is correct
5 Correct 203 ms 186316 KB Output is correct
6 Correct 174 ms 186156 KB Output is correct
7 Correct 165 ms 186316 KB Output is correct
8 Correct 178 ms 186164 KB Output is correct
9 Correct 172 ms 186316 KB Output is correct
10 Correct 173 ms 186260 KB Output is correct
11 Correct 175 ms 186316 KB Output is correct
12 Correct 177 ms 186312 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 460 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 456 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 456 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 456 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 344 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 0 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 1 ms 344 KB Output is correct
64 Correct 1 ms 348 KB Output is correct
65 Correct 0 ms 604 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 460 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 1 ms 856 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 604 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 0 ms 432 KB Output is correct
80 Correct 1 ms 348 KB Output is correct
81 Correct 0 ms 348 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 1 ms 384 KB Output is correct
86 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 460 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 456 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 344 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 456 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 456 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 1 ms 344 KB Output is correct
55 Correct 1 ms 344 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 181 ms 186300 KB Output is correct
58 Correct 176 ms 186140 KB Output is correct
59 Correct 173 ms 186128 KB Output is correct
60 Correct 182 ms 186316 KB Output is correct
61 Correct 203 ms 186316 KB Output is correct
62 Correct 174 ms 186156 KB Output is correct
63 Correct 165 ms 186316 KB Output is correct
64 Correct 178 ms 186164 KB Output is correct
65 Correct 172 ms 186316 KB Output is correct
66 Correct 173 ms 186260 KB Output is correct
67 Correct 175 ms 186316 KB Output is correct
68 Correct 177 ms 186312 KB Output is correct
69 Correct 0 ms 344 KB Output is correct
70 Correct 1 ms 344 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 1 ms 344 KB Output is correct
77 Correct 1 ms 348 KB Output is correct
78 Correct 0 ms 604 KB Output is correct
79 Correct 1 ms 348 KB Output is correct
80 Correct 1 ms 348 KB Output is correct
81 Correct 0 ms 348 KB Output is correct
82 Correct 0 ms 348 KB Output is correct
83 Correct 1 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 0 ms 460 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 1 ms 856 KB Output is correct
88 Correct 1 ms 604 KB Output is correct
89 Correct 1 ms 604 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 0 ms 348 KB Output is correct
92 Correct 0 ms 432 KB Output is correct
93 Correct 1 ms 348 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 0 ms 348 KB Output is correct
98 Correct 1 ms 384 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 92 ms 76748 KB Output is correct
101 Correct 90 ms 76748 KB Output is correct
102 Correct 86 ms 76588 KB Output is correct
103 Correct 81 ms 76564 KB Output is correct
104 Correct 84 ms 76540 KB Output is correct
105 Correct 127 ms 113352 KB Output is correct
106 Correct 118 ms 113100 KB Output is correct
107 Correct 121 ms 113096 KB Output is correct
108 Correct 114 ms 113184 KB Output is correct
109 Correct 116 ms 113096 KB Output is correct
110 Correct 93 ms 76592 KB Output is correct
111 Correct 91 ms 76748 KB Output is correct
112 Correct 88 ms 76748 KB Output is correct
113 Correct 87 ms 76744 KB Output is correct
114 Correct 89 ms 76600 KB Output is correct
115 Correct 167 ms 186200 KB Output is correct
116 Correct 174 ms 186312 KB Output is correct
117 Correct 168 ms 186140 KB Output is correct
118 Correct 167 ms 186316 KB Output is correct
119 Correct 169 ms 186152 KB Output is correct
120 Correct 87 ms 76748 KB Output is correct
121 Correct 93 ms 76584 KB Output is correct
122 Correct 90 ms 76748 KB Output is correct
123 Correct 90 ms 76744 KB Output is correct
124 Correct 123 ms 131528 KB Output is correct
125 Correct 122 ms 131520 KB Output is correct
126 Correct 122 ms 131416 KB Output is correct
127 Correct 146 ms 131436 KB Output is correct
128 Correct 41 ms 40420 KB Output is correct
129 Correct 39 ms 40404 KB Output is correct
130 Correct 39 ms 40404 KB Output is correct
131 Correct 1 ms 348 KB Output is correct