Submission #1088637

#TimeUsernameProblemLanguageResultExecution timeMemory
1088637_8_8_Homework (CEOI22_homework)C++17
100 / 100
190 ms175564 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, val[N], l[N], r[N]; vector<int> st, g[N]; bool ok[N]; void dfs(int v) { if(v <= col) { l[v] = 1, r[v] = col; return; } for(int to:g[v]) { dfs(to); } if(ok[v]) { r[v] = max(r[g[v][0]], r[g[v][1]]); l[v] = l[g[v][0]] + l[g[v][1]]; } else { l[v] = min(l[g[v][0]], l[g[v][1]]); r[v] = col - ((col - r[g[v][0]] + 1) + (col - r[g[v][1]] + 1)) + 1; } } 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 = col + 1; i <= n; i++) { int f = (int)g[i].size(); for(int j = 0; j < 2 - f; j++) { g[i].push_back(++it); } } dfs(col + 1); cout << r[col + 1] - l[col + 1] + 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...