Submission #1083248

#TimeUsernameProblemLanguageResultExecution timeMemory
1083248shiocanHomework (CEOI22_homework)C++17
100 / 100
123 ms85728 KiB
#include <bits/stdc++.h>
#include <cstdlib>
#include <stdlib.h>
using namespace std;
/*
    #define cin fin
    #define cout fout
    string __fname = ""; ifstream fin(__fname + ".in"); ofstream fout(__fname + ".out");
*/
#define ull unsigned long long 
#define ll long long
#define int long long
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
int mod = 1e9 + 7; 
const int inf = 1e18;
const int N = 1e6 + 10;

int n;
pii fun(){
    char a, b, c, d;
    cin >> a;

    if(a == '?'){
        n++;
        return {0, 0};
    }

    cin >> b >> c >> d;

    bool mx = b == 'a';

    pii p1 = fun();
    cin >> d;
    pii p2 = fun();
    cin >> d;

    if(mx)
        return {p1.first + p2.first + 1, min(p1.second, p2.second)};
    return {min(p1.first, p2.first), p1.second + p2.second + 1};        
    
}

void solve(){

    pii p = fun();

    cout << n - p.first - p.second << '\n';
}

int32_t main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    // cin >> t;
    while(t--)
        solve();
    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...