Submission #970027

#TimeUsernameProblemLanguageResultExecution timeMemory
97002712345678Homework (CEOI22_homework)C++17
53 / 100
194 ms157836 KiB
#include <bits/stdc++.h> using namespace std; const int nx=1e6+5; int n, t[nx], sz[nx], mn[nx], mx[nx], cnt; vector<int> d[nx]; string s; int build(int l, int i) { if (s[l]=='?') return l; if (s[l+1]=='i') t[i]=1; else t[i]=2; d[i].push_back(++cnt); int tmp=build(l+4, cnt); l=tmp+2; d[i].push_back(++cnt); tmp=build(l, cnt); return tmp+1; } void solve(int i) { if (t[i]==0) return sz[i]=mn[i]=mx[i]=1, void(); solve(d[i][0]); solve(d[i][1]); sz[i]=sz[d[i][0]]+sz[d[i][1]]; if (t[i]==1) { mn[i]=min(mn[d[i][0]], mn[d[i][1]]); mx[i]=mx[d[i][0]]+mx[d[i][1]]-1; } if (t[i]==2) { mn[i]=mn[d[i][0]]+mn[d[i][1]]; mx[i]=max(sz[d[i][0]]+mx[d[i][1]], mx[d[i][0]]+sz[d[i][1]]); } //cout<<"debug "<<i<<' '<<mn[i]<<' '<<mx[i]<<'\n'; } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>s; cnt=1; n=s.size(); build(0, 1); solve(1); cout<<mx[1]-mn[1]+1; }
#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...