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;
int n;
vector<int> ara;
vector<int> son;
string str;
pair<int,int> solve(int l, int r){
if (r-l+1==1){
return {1,n};
}
pair<int,int> lnode=solve(l+4,ara[l]-1);
pair<int,int> rnode=solve(ara[l]+1,son[l]-1);
pair<int,int> don={min(lnode.first,rnode.first),max(lnode.second,rnode.second)};
pair<int,int> orig = don;
if (str[l+1]=='a'){
don.first=lnode.first+rnode.first;
}
else {
int hh = n-lnode.second+1;
int hh2 = n-rnode.second+1;
don.second=n-(hh+hh2)+1;
}
return don;
}
int main(){
cin>>str;
ara.resize(str.length(),-1);
son.resize(str.length(),-1);
n = (str.length()+6)/7;
vector<int> poses;
for (int i = 0; i < str.length(); i++){
if (str[i]=='(') poses.push_back(i-3);
if (str[i]==',') ara[poses.back()]=i;
if (str[i]==')') {
son[poses.back()]=i;
poses.pop_back();
}
}
pair<int,int> ans = solve(0,str.length()-1);
cout<<ans.second-ans.first+1<<endl;
}
Compilation message (stderr)
Main.cpp: In function 'std::pair<int, int> solve(int, int)':
Main.cpp:14:16: warning: variable 'orig' set but not used [-Wunused-but-set-variable]
14 | pair<int,int> orig = don;
| ^~~~
Main.cpp: In function 'int main()':
Main.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int i = 0; i < str.length(); i++){
| ~~^~~~~~~~~~~~~~
# | 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... |