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 ll = long long;
#define all(x) (x).begin(), (x).end()
array<int, 3> comb(array<int, 3> a, array<int, 3> b, char tp) {
if (tp == 'i')
return {min(a[0], b[0]), a[1] + b[1], a[2] + b[2]};
else
return {a[0] + b[0] + 1, max(a[2] + b[1], b[2] + a[1]), a[2] + b[2]};
}
int main() {
cin.tie(0)->sync_with_stdio(false);
string s;
cin >> s;
stack<array<int, 3>> st;
array<int, 3> cur = {-1, -1, -1};
for (int i = s.size() - 1; i >= 0; i--) {
if (s[i] == ')')
st.push({-1, -1, -1});
else if (s[i] == '?')
cur = {0, 0, 1};
else if (s[i] == ',') {
st.top() = cur;
cur = {-1, -1, -1};
}
else if (s[i] == '(') {
cur = comb(st.top(), cur, s[i - 2]);
st.pop();
i -= 3;
}
}
cout << cur[1] - cur[0] + 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... |