이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 = a.st + b.st;
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... |