Submission #1086527

#TimeUsernameProblemLanguageResultExecution timeMemory
1086527juicyHomework (CEOI22_homework)C++17
100 / 100
64 ms81256 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...