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=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 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... |