답안 #1011200

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011200 2024-06-30T05:16:55 Z Forested Homework (CEOI22_homework) C++17
100 / 100
284 ms 186556 KB
#include <bits/stdc++.h>
using namespace std;
using i32 = int;
using i64 = long long;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = V<V<T>>;
#define OVERRIDE4(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32)(n); ++i)
#define REP3(i, l, r) for (i32 i = (i32)(l); i < (i32)(r); ++i)
#define REP(...) OVERRIDE4(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER2(i, n) for (i32 i = (i32)(n) - 1; i >= 0; --i)
#define PER3(i, l, r) for (i32 i = (i32)(r) - 1; i >= (i32)(l); --i)
#define PER(...) OVERRIDE4(__VA_ARGS__, PER3, PER2)(__VA_ARGS__)
#define LEN(x) (i32)size(x)
#define ALL(x) begin(x), end(x)
template <typename T>
bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

enum class Type {
    Question,
    Min,
    Max
};

struct Node {
    Type ty;
    Node *lch, *rch;
};

Node *parse(string &s, i32 &pos) {
    Node *ret = new Node;
    if (s[pos] == '?') {
        ++pos;
        ret->ty = Type::Question;
        ret->lch = nullptr;
        ret->rch = nullptr;
        return ret;
    }
    if (s[pos + 1] == 'i') {
        ret->ty = Type::Min;
    } else {
        ret->ty = Type::Max;
    }
    pos += 4;
    ret->lch = parse(s, pos);
    ++pos;
    ret->rch = parse(s, pos);
    ++pos;
    return ret;
}

// can make [low, high)
struct DP {
    i32 cnt, low, high;
};

DP dp(Node *node) {
    if (node->ty == Type::Question) {
        return DP{1, 0, 1};
    }
    DP ldp = dp(node->lch);
    DP rdp = dp(node->rch);
    DP ret;
    ret.cnt = ldp.cnt + rdp.cnt;
    if (node->ty == Type::Min) {
        ret.low = min(ldp.low, rdp.low);
        ret.high = ret.cnt - (ldp.cnt - ldp.high + rdp.cnt - rdp.high + 1);
    } else {
        ret.low = ldp.low + rdp.low + 1;
        ret.high = ret.cnt - min(ldp.cnt - ldp.high, rdp.cnt - rdp.high);
    }
    return ret;
}

int main() {
    string s;
    cin >> s;
    i32 n = count(ALL(s), '?');
    i32 pos = 0;
    Node *tree = parse(s, pos);
    DP d = dp(tree);
    i32 ans = d.high - d.low;
    cout << ans << '\n';
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:94:9: warning: unused variable 'n' [-Wunused-variable]
   94 |     i32 n = count(ALL(s), '?');
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 428 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 600 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 428 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 600 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 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 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 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 0 ms 348 KB Output is correct
36 Correct 0 ms 436 KB Output is correct
37 Correct 0 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 348 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 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 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 0 ms 348 KB Output is correct
55 Correct 0 ms 440 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 284 ms 186172 KB Output is correct
2 Correct 254 ms 186288 KB Output is correct
3 Correct 248 ms 186556 KB Output is correct
4 Correct 242 ms 186200 KB Output is correct
5 Correct 238 ms 186236 KB Output is correct
6 Correct 249 ms 186284 KB Output is correct
7 Correct 241 ms 186192 KB Output is correct
8 Correct 240 ms 186288 KB Output is correct
9 Correct 243 ms 186264 KB Output is correct
10 Correct 243 ms 186224 KB Output is correct
11 Correct 234 ms 186144 KB Output is correct
12 Correct 229 ms 186196 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 428 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 600 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 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 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 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 0 ms 348 KB Output is correct
36 Correct 0 ms 436 KB Output is correct
37 Correct 0 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 348 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 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 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 0 ms 348 KB Output is correct
55 Correct 0 ms 440 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 1 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 0 ms 348 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 1 ms 344 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 1 ms 344 KB Output is correct
68 Correct 0 ms 348 KB Output is correct
69 Correct 1 ms 344 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 0 ms 604 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 0 ms 508 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 1 ms 348 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 1 ms 348 KB Output is correct
81 Correct 1 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 0 ms 348 KB Output is correct
86 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 0 ms 428 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 600 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 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 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 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 0 ms 348 KB Output is correct
36 Correct 0 ms 436 KB Output is correct
37 Correct 0 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 348 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 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 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 0 ms 348 KB Output is correct
55 Correct 0 ms 440 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 284 ms 186172 KB Output is correct
58 Correct 254 ms 186288 KB Output is correct
59 Correct 248 ms 186556 KB Output is correct
60 Correct 242 ms 186200 KB Output is correct
61 Correct 238 ms 186236 KB Output is correct
62 Correct 249 ms 186284 KB Output is correct
63 Correct 241 ms 186192 KB Output is correct
64 Correct 240 ms 186288 KB Output is correct
65 Correct 243 ms 186264 KB Output is correct
66 Correct 243 ms 186224 KB Output is correct
67 Correct 234 ms 186144 KB Output is correct
68 Correct 229 ms 186196 KB Output is correct
69 Correct 0 ms 344 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 1 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 0 ms 348 KB Output is correct
77 Correct 1 ms 344 KB Output is correct
78 Correct 1 ms 344 KB Output is correct
79 Correct 0 ms 348 KB Output is correct
80 Correct 1 ms 344 KB Output is correct
81 Correct 0 ms 348 KB Output is correct
82 Correct 1 ms 344 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 1 ms 348 KB Output is correct
85 Correct 0 ms 604 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 0 ms 508 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 1 ms 348 KB Output is correct
92 Correct 0 ms 348 KB Output is correct
93 Correct 1 ms 348 KB Output is correct
94 Correct 1 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 0 ms 348 KB Output is correct
99 Correct 1 ms 348 KB Output is correct
100 Correct 162 ms 76660 KB Output is correct
101 Correct 163 ms 76952 KB Output is correct
102 Correct 156 ms 76624 KB Output is correct
103 Correct 153 ms 76616 KB Output is correct
104 Correct 163 ms 76716 KB Output is correct
105 Correct 185 ms 113116 KB Output is correct
106 Correct 186 ms 113176 KB Output is correct
107 Correct 175 ms 113076 KB Output is correct
108 Correct 185 ms 113044 KB Output is correct
109 Correct 180 ms 113228 KB Output is correct
110 Correct 154 ms 76636 KB Output is correct
111 Correct 176 ms 76704 KB Output is correct
112 Correct 201 ms 76628 KB Output is correct
113 Correct 153 ms 76560 KB Output is correct
114 Correct 156 ms 76720 KB Output is correct
115 Correct 230 ms 186288 KB Output is correct
116 Correct 237 ms 186288 KB Output is correct
117 Correct 230 ms 186124 KB Output is correct
118 Correct 214 ms 186292 KB Output is correct
119 Correct 238 ms 186456 KB Output is correct
120 Correct 154 ms 76640 KB Output is correct
121 Correct 158 ms 76716 KB Output is correct
122 Correct 165 ms 76652 KB Output is correct
123 Correct 157 ms 76564 KB Output is correct
124 Correct 187 ms 131504 KB Output is correct
125 Correct 189 ms 131296 KB Output is correct
126 Correct 190 ms 131504 KB Output is correct
127 Correct 184 ms 131508 KB Output is correct
128 Correct 77 ms 40384 KB Output is correct
129 Correct 78 ms 40380 KB Output is correct
130 Correct 77 ms 40380 KB Output is correct
131 Correct 0 ms 344 KB Output is correct