Submission #1088037

#TimeUsernameProblemLanguageResultExecution timeMemory
1088037_8_8_Homework (CEOI22_homework)C++17
0 / 100
164 ms158908 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e6 + 12, MOD = 998244353; string s; int m, n, col, l[N], r[N]; vector<int> st, g[N]; bool ok[N]; void dfs(int v) { if(v <= col) return; for(int to:g[v]) { dfs(to); } if(ok[v]) { l[v] = max(l[g[v][0]], l[g[v][1]]); r[v] = max(r[g[v][0]], r[g[v][1]]); if(l[g[v][0]] == l[g[v][1]]) { l[v]++; } } else { r[v] = min(r[g[v][0]], r[g[v][1]]); if(r[g[v][0]] == r[g[v][1]]) { r[v]--; } l[v] = min(l[g[v][0]], l[g[v][1]]); } // cout << v << ' ' << l[v] << ' ' << r[v] << '\n'; } void test() { cin >> s; m = (int)s.size(); for(int i = 0; i < m; i++) { if(s[i] == '?') { col++; } } n = col; for(int i = 0; i < m; i++) { if(s[i] == '(') { if(!st.empty()) { g[st.back()].push_back(n + 1); } st.push_back(++n); if(s[i - 1] == 'x') { ok[n] = 1; } } else if(s[i] == ')') { st.pop_back(); } } int it = 0; // (()()) for(int i = 1; i <= col; i++) { l[i] = 1,r[i] = col; } for(int i = col + 1; i <= n; i++) { int f = (int)g[i].size(); for(int j = 0; j < 2 - f; j++) { g[i].push_back(++it); } } assert(it == col); dfs(col + 1); cout << r[col + 1] - l[col + 1] << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; // cin >> t; while(t--) test(); 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...