Submission #651028

#TimeUsernameProblemLanguageResultExecution timeMemory
651028AntekbHomework (CEOI22_homework)C++14
100 / 100
248 ms123596 KiB
#include<bits/stdc++.h>
 
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("trapv")
 
#define st first
#define nd second
#define pb push_back
#define pp pop_back
#define eb emplace_back
#define mp(a, b) make_pair(a, b)
#define all(x) (x).begin(), (x).end()
#define rev(x) reverse(all(x))
#define sor(x) sort(all(x))
#define sz(x) (int)(x).size()
#define rsz(x) resize(x)
 
using namespace std;
 
///~~~~~~~~~~~~~~~~~~~~~~~~~~
 
template <typename H, typename T> 
ostream& operator<<(ostream& os, pair<H, T> m){
	return os <<"("<< m.st<<", "<<m.nd<<")";
}
template <typename H> 
ostream& operator<<(ostream& os, vector<H> V){
	os<<"{";
	for(int i=0; i<V.size(); i++){
		if(i)os<<" ";
		os<<V[i];
	}
	os<<"}";
	return os;
}
 
void debug(){cerr<<"\n";}
template <typename H, typename... T>
void debug(H h, T... t) {cerr<<h; if (sizeof...(t)) cerr << ", "; debug(t...);}
#define deb(x...) cerr<<#x<<" = ";debug(x);
 
///~~~~~~~~~~~~~~~~~~~~~~~~~
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii > vii;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef string str;
 
#define BOOST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
 
const int N=2e5+5, INF=1e9+5, mod=1e9+7;
string s;
int wsk;
pair<int, pii> solve(){
	if(s[wsk]=='?'){
		wsk++;
		return mp(1, mp(0, 0));
	}
	bool c=0;
	if(s[wsk+1]=='a')c=1;
	wsk+=4;
	auto a=solve();
	wsk++;
	auto b=solve();
	wsk++;
	if(c)return mp(a.st+b.st+max(a.nd.nd,b.nd.nd)-1, mp(a.nd.st+b.nd.st+1, min(a.nd.nd, b.nd.nd)));
	else return mp(a.st+b.st+max(a.nd.st,b.nd.st)-1, mp(min(a.nd.st,b.nd.st), a.nd.nd+b.nd.nd+1));
}
int main(){
	//BOOST;
	cin>>s;
	cout<<solve().st;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...