답안 #830160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
830160 2023-08-18T20:48:29 Z themm1 Homework (CEOI22_homework) C++17
100 / 100
177 ms 147456 KB
#include <bits/stdc++.h>
using namespace std;
// ordered set whith s.order_of_key(x) method, which returns rank of element x in set s
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
*/

// pair printing
template <class T, class U>
ostream& operator<<(ostream& out, const pair<T, U> &par) {out << "(" << par.first << "; " << par.second << ")"; return out;}
// set printing
template <class T>
ostream& operator<<(ostream& out, const set<T> &cont) { out << "{"; for(const auto &x:cont) out << x << ", "; out << "}"; return out; }
// map printing
template <class T, class U>
ostream& operator<<(ostream& out, const map<T, U> &cont) {out << "{"; for(const auto &x:cont) out << x << ", "; out << "}"; return out; }
// unordered_set printing
template <class T>
ostream& operator<<(ostream& out, const unordered_set<T> &cont) {out << "{";for(const auto &x:cont) out << x << ", ";out << "}";return out;}
// unordered_map printing
template <class T, class U>
ostream& operator<<(ostream& out, const unordered_map<T, U> &cont) {out << "{";for(const auto &x:cont) out << x << ", ";out << "}";return out;}
// vector printing
template<class T>
ostream& operator<<(ostream& out, const vector<T> &cont){ out << "[";  for (const auto &x:cont) out << x << ", ";  out << "]"; return out;}

#define print(x) cout << (x) << endl;
#define dmp(x) cerr << #x << " = " << x << endl
#define dmpn(x) cerr << #x << " = " << x << "; "
#define dmpl(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << x << endl

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define pb push_back
#define ff first
#define ss second
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define contains(s,x) ((s).find(x) != (s).end())
const int MOD = 998244353;

int N, M;
vector<int> parents;
vector<vector<int>> children;
vector<bool> is_min;

pii dfs(int v) {
        if (children[v].empty()) return { 1, M };
        pii a = dfs(children[v][0]);
        pii b = dfs(children[v][1]);
        // dmpn(v); dmpn(a); dmp(b);
        int new_min, new_max;
        if (is_min[v]) {
                new_min = min(a.ff, b.ff);
                new_max = a.ss - (M - b.ss + 1);
        } else {
                new_min = a.ff + b.ff;
                new_max = max(a.ss, b.ss);
        }
        return { new_min, new_max };
}

void solve() {
        string s;
        cin >> s;
        M = count(all(s), '?');
        N = M + count(all(s), 'm');
        // dmpn(N); dmp(M);

        parents.assign(N, -1);
        children.resize(N);
        is_min.resize(N);
        int v = -1, maxv = -1;
        for (int i = 0; i < sz(s); i++) {
                if (s[i] == '(') {
                        maxv++;
                        // dmp(maxv);
                        if (v != -1) children[v].pb(maxv);
                        parents[maxv] = v;
                        v = maxv;
                        is_min[v] = (s[i - 1] == 'n');
                } else if (s[i] == ')') {
                        // dmp(v);
                        v = parents[v];
                } else if (s[i] == '?') {
                        maxv++;
                        // dmp(maxv);
                        children[v].pb(maxv);
                        parents[maxv] = v;
                        // dmp(maxv);
                }
        }
        pii p = dfs(0);
        cout << p.ss - p.ff + 1 << endl;
}

int32_t main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);

        int t = 1;
        // cin >> t;
        while (t--) {
                solve();
        }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 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 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 324 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 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 320 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 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 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 324 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 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 320 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 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 320 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 244 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 320 KB Output is correct
35 Correct 1 ms 320 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 320 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 304 KB Output is correct
44 Correct 0 ms 320 KB Output is correct
45 Correct 1 ms 212 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 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 316 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 316 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 166 ms 147224 KB Output is correct
2 Correct 162 ms 147420 KB Output is correct
3 Correct 173 ms 147328 KB Output is correct
4 Correct 173 ms 147216 KB Output is correct
5 Correct 164 ms 147208 KB Output is correct
6 Correct 167 ms 147208 KB Output is correct
7 Correct 161 ms 147268 KB Output is correct
8 Correct 163 ms 147248 KB Output is correct
9 Correct 166 ms 147396 KB Output is correct
10 Correct 164 ms 147312 KB Output is correct
11 Correct 161 ms 147208 KB Output is correct
12 Correct 176 ms 147456 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 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 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 324 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 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 320 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 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 320 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 244 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 320 KB Output is correct
35 Correct 1 ms 320 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 320 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 304 KB Output is correct
44 Correct 0 ms 320 KB Output is correct
45 Correct 1 ms 212 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 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 316 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 316 KB Output is correct
55 Correct 0 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 0 ms 324 KB Output is correct
59 Correct 1 ms 340 KB Output is correct
60 Correct 1 ms 340 KB Output is correct
61 Correct 0 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 340 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 1 ms 340 KB Output is correct
71 Correct 0 ms 340 KB Output is correct
72 Correct 0 ms 468 KB Output is correct
73 Correct 1 ms 452 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 0 ms 340 KB Output is correct
79 Correct 0 ms 340 KB Output is correct
80 Correct 1 ms 340 KB Output is correct
81 Correct 0 ms 340 KB Output is correct
82 Correct 1 ms 340 KB Output is correct
83 Correct 0 ms 340 KB Output is correct
84 Correct 1 ms 340 KB Output is correct
85 Correct 0 ms 340 KB Output is correct
86 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 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 316 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 324 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 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 320 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 1 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 320 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 244 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 320 KB Output is correct
35 Correct 1 ms 320 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 320 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 0 ms 304 KB Output is correct
44 Correct 0 ms 320 KB Output is correct
45 Correct 1 ms 212 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 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 1 ms 212 KB Output is correct
51 Correct 0 ms 212 KB Output is correct
52 Correct 0 ms 316 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 0 ms 316 KB Output is correct
55 Correct 0 ms 212 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 166 ms 147224 KB Output is correct
58 Correct 162 ms 147420 KB Output is correct
59 Correct 173 ms 147328 KB Output is correct
60 Correct 173 ms 147216 KB Output is correct
61 Correct 164 ms 147208 KB Output is correct
62 Correct 167 ms 147208 KB Output is correct
63 Correct 161 ms 147268 KB Output is correct
64 Correct 163 ms 147248 KB Output is correct
65 Correct 166 ms 147396 KB Output is correct
66 Correct 164 ms 147312 KB Output is correct
67 Correct 161 ms 147208 KB Output is correct
68 Correct 176 ms 147456 KB Output is correct
69 Correct 0 ms 212 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 0 ms 324 KB Output is correct
72 Correct 1 ms 340 KB Output is correct
73 Correct 1 ms 340 KB Output is correct
74 Correct 0 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 0 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 1 ms 340 KB Output is correct
84 Correct 0 ms 340 KB Output is correct
85 Correct 0 ms 468 KB Output is correct
86 Correct 1 ms 452 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 0 ms 340 KB Output is correct
92 Correct 0 ms 340 KB Output is correct
93 Correct 1 ms 340 KB Output is correct
94 Correct 0 ms 340 KB Output is correct
95 Correct 1 ms 340 KB Output is correct
96 Correct 0 ms 340 KB Output is correct
97 Correct 1 ms 340 KB Output is correct
98 Correct 0 ms 340 KB Output is correct
99 Correct 0 ms 212 KB Output is correct
100 Correct 144 ms 100352 KB Output is correct
101 Correct 146 ms 100260 KB Output is correct
102 Correct 138 ms 100236 KB Output is correct
103 Correct 135 ms 100260 KB Output is correct
104 Correct 136 ms 100408 KB Output is correct
105 Correct 163 ms 115980 KB Output is correct
106 Correct 160 ms 115996 KB Output is correct
107 Correct 156 ms 116140 KB Output is correct
108 Correct 154 ms 116004 KB Output is correct
109 Correct 151 ms 116012 KB Output is correct
110 Correct 148 ms 100248 KB Output is correct
111 Correct 148 ms 100252 KB Output is correct
112 Correct 145 ms 100380 KB Output is correct
113 Correct 157 ms 100312 KB Output is correct
114 Correct 147 ms 100248 KB Output is correct
115 Correct 177 ms 147248 KB Output is correct
116 Correct 171 ms 147232 KB Output is correct
117 Correct 163 ms 147228 KB Output is correct
118 Correct 168 ms 147260 KB Output is correct
119 Correct 164 ms 147268 KB Output is correct
120 Correct 152 ms 100236 KB Output is correct
121 Correct 142 ms 100372 KB Output is correct
122 Correct 153 ms 100332 KB Output is correct
123 Correct 151 ms 100316 KB Output is correct
124 Correct 145 ms 123740 KB Output is correct
125 Correct 141 ms 123800 KB Output is correct
126 Correct 142 ms 123800 KB Output is correct
127 Correct 142 ms 123808 KB Output is correct
128 Correct 72 ms 52756 KB Output is correct
129 Correct 70 ms 52736 KB Output is correct
130 Correct 65 ms 52760 KB Output is correct
131 Correct 0 ms 212 KB Output is correct