#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;
}
i32 eval(Node *node, const V<i32> &p, i32 &pos) {
if (node->ty == Type::Question) {
return p[pos++];
} else {
i32 lv = eval(node->lch, p, pos);
i32 rv = eval(node->rch, p, pos);
if (node->ty == Type::Min) {
return min(lv, rv);
} else {
return max(lv, rv);
}
}
}
int main() {
string s;
cin >> s;
i32 n = count(ALL(s), '?');
assert(n <= 9);
i32 pos = 0;
Node *tree = parse(s, pos);
V<i32> can(n, 0);
V<i32> p(n);
iota(ALL(p), 0);
do {
pos = 0;
can[eval(tree, p, pos)] = 1;
} while (next_permutation(ALL(p)));
i32 ans = accumulate(ALL(can), 0);
cout << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
348 KB |
Output is correct |
2 |
Correct |
14 ms |
344 KB |
Output is correct |
3 |
Correct |
15 ms |
436 KB |
Output is correct |
4 |
Correct |
14 ms |
600 KB |
Output is correct |
5 |
Correct |
16 ms |
348 KB |
Output is correct |
6 |
Correct |
14 ms |
348 KB |
Output is correct |
7 |
Correct |
14 ms |
348 KB |
Output is correct |
8 |
Correct |
15 ms |
432 KB |
Output is correct |
9 |
Correct |
14 ms |
348 KB |
Output is correct |
10 |
Correct |
20 ms |
436 KB |
Output is correct |
11 |
Correct |
14 ms |
348 KB |
Output is correct |
12 |
Correct |
14 ms |
432 KB |
Output is correct |
13 |
Correct |
15 ms |
348 KB |
Output is correct |
14 |
Correct |
14 ms |
436 KB |
Output is correct |
15 |
Correct |
15 ms |
344 KB |
Output is correct |
16 |
Correct |
15 ms |
348 KB |
Output is correct |
17 |
Correct |
18 ms |
436 KB |
Output is correct |
18 |
Correct |
15 ms |
436 KB |
Output is correct |
19 |
Correct |
14 ms |
352 KB |
Output is correct |
20 |
Correct |
15 ms |
348 KB |
Output is correct |
21 |
Correct |
15 ms |
348 KB |
Output is correct |
22 |
Correct |
14 ms |
348 KB |
Output is correct |
23 |
Correct |
15 ms |
348 KB |
Output is correct |
24 |
Correct |
14 ms |
436 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
348 KB |
Output is correct |
2 |
Correct |
14 ms |
344 KB |
Output is correct |
3 |
Correct |
15 ms |
436 KB |
Output is correct |
4 |
Correct |
14 ms |
600 KB |
Output is correct |
5 |
Correct |
16 ms |
348 KB |
Output is correct |
6 |
Correct |
14 ms |
348 KB |
Output is correct |
7 |
Correct |
14 ms |
348 KB |
Output is correct |
8 |
Correct |
15 ms |
432 KB |
Output is correct |
9 |
Correct |
14 ms |
348 KB |
Output is correct |
10 |
Correct |
20 ms |
436 KB |
Output is correct |
11 |
Correct |
14 ms |
348 KB |
Output is correct |
12 |
Correct |
14 ms |
432 KB |
Output is correct |
13 |
Correct |
15 ms |
348 KB |
Output is correct |
14 |
Correct |
14 ms |
436 KB |
Output is correct |
15 |
Correct |
15 ms |
344 KB |
Output is correct |
16 |
Correct |
15 ms |
348 KB |
Output is correct |
17 |
Correct |
18 ms |
436 KB |
Output is correct |
18 |
Correct |
15 ms |
436 KB |
Output is correct |
19 |
Correct |
14 ms |
352 KB |
Output is correct |
20 |
Correct |
15 ms |
348 KB |
Output is correct |
21 |
Correct |
15 ms |
348 KB |
Output is correct |
22 |
Correct |
14 ms |
348 KB |
Output is correct |
23 |
Correct |
15 ms |
348 KB |
Output is correct |
24 |
Correct |
14 ms |
436 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 6 |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
102 ms |
21424 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
348 KB |
Output is correct |
2 |
Correct |
14 ms |
344 KB |
Output is correct |
3 |
Correct |
15 ms |
436 KB |
Output is correct |
4 |
Correct |
14 ms |
600 KB |
Output is correct |
5 |
Correct |
16 ms |
348 KB |
Output is correct |
6 |
Correct |
14 ms |
348 KB |
Output is correct |
7 |
Correct |
14 ms |
348 KB |
Output is correct |
8 |
Correct |
15 ms |
432 KB |
Output is correct |
9 |
Correct |
14 ms |
348 KB |
Output is correct |
10 |
Correct |
20 ms |
436 KB |
Output is correct |
11 |
Correct |
14 ms |
348 KB |
Output is correct |
12 |
Correct |
14 ms |
432 KB |
Output is correct |
13 |
Correct |
15 ms |
348 KB |
Output is correct |
14 |
Correct |
14 ms |
436 KB |
Output is correct |
15 |
Correct |
15 ms |
344 KB |
Output is correct |
16 |
Correct |
15 ms |
348 KB |
Output is correct |
17 |
Correct |
18 ms |
436 KB |
Output is correct |
18 |
Correct |
15 ms |
436 KB |
Output is correct |
19 |
Correct |
14 ms |
352 KB |
Output is correct |
20 |
Correct |
15 ms |
348 KB |
Output is correct |
21 |
Correct |
15 ms |
348 KB |
Output is correct |
22 |
Correct |
14 ms |
348 KB |
Output is correct |
23 |
Correct |
15 ms |
348 KB |
Output is correct |
24 |
Correct |
14 ms |
436 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 6 |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
348 KB |
Output is correct |
2 |
Correct |
14 ms |
344 KB |
Output is correct |
3 |
Correct |
15 ms |
436 KB |
Output is correct |
4 |
Correct |
14 ms |
600 KB |
Output is correct |
5 |
Correct |
16 ms |
348 KB |
Output is correct |
6 |
Correct |
14 ms |
348 KB |
Output is correct |
7 |
Correct |
14 ms |
348 KB |
Output is correct |
8 |
Correct |
15 ms |
432 KB |
Output is correct |
9 |
Correct |
14 ms |
348 KB |
Output is correct |
10 |
Correct |
20 ms |
436 KB |
Output is correct |
11 |
Correct |
14 ms |
348 KB |
Output is correct |
12 |
Correct |
14 ms |
432 KB |
Output is correct |
13 |
Correct |
15 ms |
348 KB |
Output is correct |
14 |
Correct |
14 ms |
436 KB |
Output is correct |
15 |
Correct |
15 ms |
344 KB |
Output is correct |
16 |
Correct |
15 ms |
348 KB |
Output is correct |
17 |
Correct |
18 ms |
436 KB |
Output is correct |
18 |
Correct |
15 ms |
436 KB |
Output is correct |
19 |
Correct |
14 ms |
352 KB |
Output is correct |
20 |
Correct |
15 ms |
348 KB |
Output is correct |
21 |
Correct |
15 ms |
348 KB |
Output is correct |
22 |
Correct |
14 ms |
348 KB |
Output is correct |
23 |
Correct |
15 ms |
348 KB |
Output is correct |
24 |
Correct |
14 ms |
436 KB |
Output is correct |
25 |
Correct |
2 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 6 |
30 |
Halted |
0 ms |
0 KB |
- |