This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |