Submission #1176250

#TimeUsernameProblemLanguageResultExecution timeMemory
1176250sofija6Homework (CEOI22_homework)C++20
100 / 100
54 ms38700 KiB
#include <bits/stdc++.h>
#define ll int
using namespace std;
string s;
ll n,pos;
pair<ll,ll> Solve()
{
    if (s[pos]=='?')
    {
        pos++;
        return {1,n};
    }
    ll t=0;
    if (s[pos+1]=='a')
        t=1;
    pos+=4;
    pair<ll,ll> x=Solve();
    pos++;
    pair<ll,ll> y=Solve();
    pos++;
    if (t)
        return {x.first+y.first,max(x.second,y.second)};
    return {min(x.first,y.first),x.second+y.second-n-1};
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> s;
    for (ll i=0;i<s.size();i++)
        n+=s[i]=='?';
    pair<ll,ll> ans=Solve();
    cout << ans.second-ans.first+1;
    return 0;
}
#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...