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 pii = pair <int, int>;
string s;
int question_marks, point;
pii get()
{
if(s[point] == ',' || s[point] == '(') point += 1;
if(s[point] == '?') return {1, question_marks};
if(s[point] == 'm') point += 2;
if(s[point] == 'a' || s[point] == 'i') point += 1;
bool ismax = (s[point] == 'x');
point++;
pii u = get();
point++;
pii w = get();
point++;
if(ismax)
return {u.first + w.first, max(u.second, w.second)};
else
return {min(u.first, w.first), u.second + w.second - question_marks - 1};
}
signed main()
{
cin.tie(0) -> ios_base::sync_with_stdio(0);
cin >> s;
question_marks = count(s.begin(), s.end(), '?');
pii ans = get();
cout << ans.second - ans.first + 1 << '\n';
}
# | 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... |