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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
string s; cin >> s;
int n = s.size();
vector<int> a(n), b(n);
vector<array<int, 2>> st;
int c = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == 'm') {
st.push_back({i, 0});
i += 3;
} else if (s[i] == '?') {
while (st.size() && st.back()[1]) {
int j = st.back()[0];
if (s[j + 1] == 'a') {
a[i] += a[j] + 1;
b[i] = min(b[i], b[j]);
} else {
a[i] = min(a[i], a[j]);
b[i] += b[j] + 1;
}
st.pop_back();
}
++c;
if (!st.size()) {
cout << c - a[i] - b[i];
break;
}
int l = st.back()[0];
tie(a[l], b[l]) = tie(a[i], b[i]);
st.back()[1] = 1;
}
}
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... |