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;
struct Node {
int st, dr;
int sz;
Node () {
st = 1, dr = 0;
sz = 0;
}
};
string S;
int pos = 0;
Node Join (Node a, Node b, bool op) {
Node ans;
ans.sz = a.sz + b.sz;
if (op == false) {
ans.st = min(a.st, b.st);
ans.dr = a.dr + b.dr - 1;
}
else {
ans.st = min(b.dr + a.st, b.st + a.dr);
ans.dr = max(a.dr + b.sz, a.sz + b.dr);
}
ans.sz = a.sz + b.sz;
return ans;
}
Node Eval () {
if (S[pos] == '?') {
Node ans;
ans.st = 1, ans.dr = 1, ans.sz = 1;
return ans;
}
bool op = 0;
if (S[pos] == 'm' && S[pos+1] == 'a' && S[pos+2] == 'x') op = 1;
Node a, b;
pos += 4;
a = Eval();
pos += 2;
b = Eval();
++ pos;
return Join(a, b, op);
}
int main () {
cin >> S;
Node ans = Eval();
cout << ans.dr - ans.st + 1 << '\n';
return 0;
}
# | 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... |