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>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(v) begin(v), end(v)
using namespace std;
using ll = long long;
template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; }
template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; }
struct Data {
int l, r, n;
};
Data expr(typename string::iterator& itr) {
if (*itr == '?') {
++itr;
return {0, 1, 1};
}
assert(*itr == 'm');
++itr;
if (*itr == 'i') {
++itr; ++itr; ++itr;
auto [l1, r1, n1] = expr(itr);
assert(*itr == ',');
++itr;
auto [l2, r2, n2] = expr(itr);
assert(*itr == ')');
++itr;
return {min(l1, l2), r1 + r2 - 1, n1 + n2};
}
else {
++itr; ++itr; ++itr;
auto [l1, r1, n1] = expr(itr);
assert(*itr == ',');
++itr;
auto [l2, r2, n2] = expr(itr);
assert(*itr == ')');
++itr;
return {l1 + l2 + 1, max(n1 + r2, n2 + r1), n1 + n2};
}
}
int main() {
string S; cin >> S;
auto itr = S.begin();
auto [l, r, n] = expr(itr);
cout << r - l << endl;
}
# | 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... |