Submission #922129

#TimeUsernameProblemLanguageResultExecution timeMemory
922129406Homework (CEOI22_homework)C++17
100 / 100
159 ms202620 KiB
#include "bits/stdc++.h" #define int long long #define FOR(i, a, b) for (int i = (a); i < (b); i++) using namespace std; const long long INF = 1ll << 60; const int N = 1e6 + 5; vector<int> nx; string S; void solve(int l, int r, int &o, int &z, int &s) { if (l == r) { o = z = 0; s = 1; return; } int o1, z1, o2, z2, s1, s2; solve(l + 4, nx[l + 4] - 1, o1, z1, s1); solve(nx[l + 4] + 1, r - 1, o2, z2, s2); s = s1 + s2; if (S[l + 2] == 'n') { //min z = z1 + z2; o = max(s1 + o2, s2 + o1); } else { // max o = o1 + o2; z = max(s1 + z2, s2 + z1); } } signed main() { ios::sync_with_stdio(0), cin.tie(0); cin >> S; nx.resize(S.size()); vector<int> st; for (int i = (int) S.size() - 2; i >= 0; i--) { if (S[i] == ',') st.push_back(i); else if (S[i] == '(') st.pop_back(); nx[i] = (st.empty() ? -1 : st.back()); } int o, z, s; solve(0, S.size() - 1, o, z, s); int ans = 0; FOR(i, 1, s+ 1) { ans += (z >= i - 1 && o >= s - i); } cout << ans << '\n'; return 0; } //Reading this fills you with DETERMINATION //13:05:50
#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...