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 T = pair<pair<int, int>, int>;
T merge(T A, T B, string f) {
if (f == "min") return {{min(A.first.first, B.first.first), A.first.second + B.first.second - 1}, A.second + B.second};
return {{A.first.first + B.first.first, max(A.second + B.first.second, A.first.second + B.second)}, A.second + B.second};
}
struct item {
string f;
vector<T> op;
} dummy;
int32_t main() {
string s;
cin >> s;
stack<item> stk;
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'm') stk.push(dummy);
if (isalpha(s[i])) stk.top().f += s[i];
if (s[i] == '?') stk.top().op.push_back({{1, 1}, 1});
if (s[i] == ')') {
assert((int) stk.top().op.size() == 2);
T rv = merge(stk.top().op[0], stk.top().op[1], stk.top().f);
stk.pop();
if (!stk.empty()) stk.top().op.push_back(rv);
else cout << rv.first.second - rv.first.first + 1 << '\n';
}
}
}
Compilation message (stderr)
Main.cpp: In function 'int32_t main()':
Main.cpp:20:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for (int i = 0; i < s.length(); i++) {
| ~~^~~~~~~~~~~~
# | 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... |