Submission #772646

#TimeUsernameProblemLanguageResultExecution timeMemory
772646dooweyHomework (CEOI22_homework)C++14
100 / 100
239 ms205888 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const int N = (int)2e6 + 10; int typ[N]; vector<int> nex[N]; /* 0 - min 1 - max 2 - ? */ int cnt[N]; int lf[N]; int rf[N]; /* void dfs0(int u){ cout << u << " -> "; if(typ[u] == 0){ cout << "min ("; } else if(typ[u] == 1){ cout << "max ("; } else{ cout << " ? "; } for(auto x : nex[u]){ cout << x << " "; } cout << ")\n"; for(auto x : nex[u]){ dfs0(x); } } */ void calc(int u){ if(typ[u] == 2){ cnt[u] = 1; lf[u]=1; rf[u]=1; } else{ for(auto x : nex[u]){ calc(x); cnt[u] += cnt[x]; } if(typ[u] == 0){ lf[u]=min(lf[nex[u][0]], lf[nex[u][1]]); rf[u]=rf[nex[u][0]]+rf[nex[u][1]]-1; } else{ rf[u]=cnt[u]-min(cnt[nex[u][0]]-rf[nex[u][0]], cnt[nex[u][1]]-rf[nex[u][1]]); lf[u]=lf[nex[u][0]]+lf[nex[u][1]]; } } } int main(){ fastIO; string s; cin >> s; if(s.size() == 1){ cout << "1\n"; return 0; } int id = 0; vector<int> stek; int cur; int las = -1; for(char x : s){ if(x == '('){ cur = id; id ++ ; if(!stek.empty()){ nex[stek.back()].push_back(cur); } typ[cur] = las; stek.push_back(cur); } else if(x == ')'){ stek.pop_back(); } else if(x == '?'){ cur = id; id ++ ; typ[cur] = 2; nex[stek.back()].push_back(cur); } else{ if('a' <= x && x <= 'z'){ if(x == 'i'){ las = 0; } else if(x == 'x'){ las = 1; } else{ continue; } } } } calc(0); cout << rf[0]-lf[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...