This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |