Submission #1326078

#TimeUsernameProblemLanguageResultExecution timeMemory
1326078sporknivesHomework (CEOI22_homework)C++20
0 / 100
1098 ms54236 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; // 1 - max, 2 - min string s; vector<int> l,r; vector<int> op; int cur = 0; void process(int a, int b, int n) { //cout<<"processing string: "<<s.substr(a,b-a+1)<<" "<<n<<'\n'; int cnt=0; if(s[a]=='?') { op[n]=-1; return; } else if(s[a+1]=='i')op[n]=0; else op[n]=1; if(s[a+4]=='?') { cur++; l[n]=cur; process(a+4,a+4,cur); cur++; r[n]=cur; process(a+6,b-1, cur); return; } int idx=-1; for(int i=a+4;i<b+1;i++) { if(s[i]=='(') cnt++; else if(s[i]==')') { cnt--; if(cnt==0) { cur++; l[n]=cur; process(a+4, i, cur); idx=i; break; } } } cur++; r[n]=cur; process(a+idx+2, b-1,cur); } vector<pii> range; vector<int> leaves; void dfs(int x) { if(op[x]==-1) { range[x]={1,1}; leaves[x]=1; return; } dfs(l[x]); dfs(r[x]); leaves[x] = leaves[l[x]] + leaves[r[x]]; if(op[x]==1) { range[x].first = range[l[x]].first + range[r[x]].first; range[x].second = leaves[x] - min(leaves[l[x]]-range[l[x]].second, leaves[r[x]]-range[r[x]].second); } else { range[x].first = min(range[l[x]].first, range[r[x]].first); range[x].second = leaves[x] - (leaves[l[x]]-range[l[x]].second) - (leaves[r[x]]-range[r[x]].second) - 1; } } int main() { cin>>s; int n = 0; for(char c: s) { if(c=='?')n++; } l.resize(2*n); r.resize(2*n); op.resize(2*n); range.resize(2*n); leaves.resize(2*n); process(0, s.length()-1, 0); dfs(0); cout<<range[0].second-range[0].first+1; 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...