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>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("popcnt")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=2e5+10,P=1e9+7;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
const ldb eps=1e-6;
const ldb PI=acos(-1.0);
const int dir[4][2]={{0,-1},{0,1},{1,0},{-1,0}};
template<typename T>
using vvector = vector<vector<T>>;
struct seg {
int a,b,c;
};
seg cal(string &s,int &x) {
if (s[x]=='?') {
x++;
return {0,1,0};
} else if (s[x+1]=='a') {
x+=4;
seg s1 = cal(s,x);
x++;
seg s2 = cal(s,x);
x++;
seg ans = {s1.a+s2.a+1,0,min(s1.c,s2.c)};
int n = s1.a+s1.b+s1.c+s2.a+s2.b+s2.c;
// cout<<s1.a<<" "<<s1.b<<" "<<s1.c<<" s1\n";
// cout<<s2.a<<" "<<s2.b<<" "<<s2.c<<" s2\n";
// cout<<ans.a<<" "<<n-ans.a-ans.c<<" "<<ans.c<<" "<<x<<"x\n";
return {ans.a,n-ans.a-ans.c,ans.c};
} else {
x+=4;
seg s1 = cal(s,x);
x++;
seg s2 = cal(s,x);
x++;
seg ans = {min(s1.a,s2.a),0,s1.c+s2.c+1};
int n = s1.a+s1.b+s1.c+s2.a+s2.b+s2.c;
// cout<<s1.a<<" "<<s1.b<<" "<<s1.c<<" s1\n";
// cout<<s2.a<<" "<<s2.b<<" "<<s2.c<<" s2\n";
// cout<<ans.a<<" "<<n-ans.a-ans.c<<" "<<ans.c<<" "<<x<<" x\n";
return {ans.a,n-ans.a-ans.c,ans.c};
}
}
int main() {
speed;
string s;
cin>>s;
int now=0;
seg ans=cal(s,now);
cout<<ans.b<<"\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... |