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;
typedef long long ll;
#define x first
#define y second
string s;
ll n=0;
pair<ll,ll> sol(ll a, ll b)
{
if(a==b) return {1,n};
ll temp=a+4;
ll pl=true;ll c1=0;
while(pl)
{
c1+=(s[temp]=='(');
c1-=(s[temp]==')');
if(c1==0&&s[temp]==',') break;
temp++;
}
pair<ll,ll> o1=sol(a+4,temp-1);
pair<ll,ll> o2=sol(temp+1,b-1);
if(s[a+2]=='n')
{
return {min(o1.x,o2.x),min(o1.y,o2.y)-1+(o1.y!=o2.y)};
}
else
{
return {max(o1.x,o2.x)+1-(o1.x!=o2.x),max(o1.y,o2.y)};
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>s;
for(auto i:s)n+=(i=='?');
cout<<(sol(0,s.size()-1).y-sol(0,s.size()-1).x);
return 0;
}
# | 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... |