#include <bits/stdc++.h>
using namespace std;
#define int long long
#define OYY LLONG_MAX
#define mod 1000000007
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR for(int i=1;i<=n;i++)
#define mid (start+end)/2
#define lim 300005
#define fi first
#define se second
#define pb push_back
int n;
string s;
int i;
inline pair<int,int> f(){
while(s[i]==',' || s[i]==')')i++;
if(s[i]=='?')return make_pair(0,0);
bool kim=0;
int mini=0,maxi=0;
if(s[i+1]=='a')kim=1;
i+=4;
pair<int,int> gec=f();
if(kim){
maxi=max(maxi,gec.fi+1);
maxi=max(maxi,gec.se);
}
else{
mini=max(mini,gec.se+1);
mini=max(mini,gec.fi);
}
i++;
while(s[i]==',' || s[i]==')')i++;
pair<int,int>gec2=f();
if(kim){
maxi=max(maxi,gec2.fi+1);
maxi=max(maxi,gec2.se);
}
else{
mini=max(mini,gec2.se+1);
mini=max(mini,gec2.fi);
}
i++;
if(!kim)mini=max(mini,gec.se+gec2.fi);
else maxi=max(maxi,gec.fi+gec2.se);
//cout<<i<<" "<<mini<<" "<<maxi<<endl;
return make_pair(mini,maxi);
}
int32_t main(){
faster
cin>>s;
n=s.length();
pair<int,int>pq=f();
int cev=max(pq.fi,pq.se);
cout<<cev<<'\n';
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... |