Submission #861227

#TimeUsernameProblemLanguageResultExecution timeMemory
861227vgtcrossHomework (CEOI22_homework)C++17
53 / 100
168 ms218272 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const int N = int(1e6) + 1000; vector<int> ch[N]; vector<int> d[N]; int l[N], r[N]; int x[N]; void solve() { string s; cin >> s; stack<pii> st; st.push({0, 0}); int w = 1; int i = 0; while (i < s.size()) { if (s[i] == '?') { ch[st.top().first].push_back(w); d[st.top().second+1].push_back(w++); } else if (s[i] == 'm') { x[w] = s[i+1] == 'a' ? 2 : 1; ch[st.top().first].push_back(w); d[st.top().second+1].push_back(w); st.push({w++, st.top().second+1}); i += 3; } else if (s[i] == ')') st.pop(); ++i; } for (int i = 1e6; i >= 0; --i) { for (int u : d[i]) { if (x[u] == 0) { l[u] = r[u] = 0; } else if (x[u] == 1) { l[u] = min(l[ch[u][0]], l[ch[u][1]]); r[u] = r[ch[u][0]] + r[ch[u][1]] + 1; } else { l[u] = l[ch[u][0]] + l[ch[u][1]] + 1; r[u] = min(r[ch[u][0]], r[ch[u][1]]); } } } int cnt = 0; for (char c : s) cnt += c == '?'; cout << cnt - l[1] - r[1] << '\n'; } int main() { cin.tie(0) -> sync_with_stdio(0); solve(); }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:23:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     while (i < s.size()) {
      |            ~~^~~~~~~~~~
#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...