Submission #879226

#TimeUsernameProblemLanguageResultExecution timeMemory
879226juliany2Homework (CEOI22_homework)C++17
100 / 100
56 ms27352 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; #define all(x) (x).begin(), (x).end() array<int, 3> comb(array<int, 3> a, array<int, 3> b, char tp) { if (tp == 'i') return {min(a[0], b[0]), a[1] + b[1], a[2] + b[2]}; else return {a[0] + b[0] + 1, max(a[2] + b[1], b[2] + a[1]), a[2] + b[2]}; } int main() { cin.tie(0)->sync_with_stdio(false); string s; cin >> s; stack<array<int, 3>> st; array<int, 3> cur = {-1, -1, -1}; for (int i = s.size() - 1; i >= 0; i--) { if (s[i] == ')') st.push({-1, -1, -1}); else if (s[i] == '?') cur = {0, 0, 1}; else if (s[i] == ',') { st.top() = cur; cur = {-1, -1, -1}; } else if (s[i] == '(') { cur = comb(st.top(), cur, s[i - 2]); st.pop(); i -= 3; } } cout << cur[1] - cur[0] + 1 << '\n'; 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...