Submission #970025

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