제출 #986963

#제출 시각아이디문제언어결과실행 시간메모리
986963aaaaaarrozHomework (CEOI22_homework)C++17
100 / 100
90 ms120156 KiB
     #include <bits/stdc++.h>
    using namespace std;
     
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef pair<ll, ll> pll;
    #define ff first
    #define ss second
    #define all(x) begin(x), end(x)
    #define rall(x) (x).rbegin(), (x).rend()
    #define sz(x) (int)(x).size()
    #define FOR(i, a, b) for(int i = (a); i < (b); i++)
    #define F0R(i, x) FOR(i, 0, x)
    #define FORd(i, a, b) for(int i = (b)-1; i >= (a); i--)
    #define F0Rd(i, x) FORd(i, 0, x)
    #define ckif(a, b, c) ((c) ? (a) : (b))
    const int MAX_N = 1e7+69;
    const ll MOD = 1000000007;
    const ll INF = 1e18;
     
    int n;
    int ql[MAX_N], qr[MAX_N], sz[MAX_N];
    string s;
     
    int dfs(int idx){
        if(s[idx] == '?'){
            idx++;
            sz[idx] = 1;
            return idx;
        }
        int num = 0;
        if(s[idx+1] == 'a') num = 1;
        idx += 4;
        idx = dfs(idx);
        int ql1 = ql[idx], qr1 = qr[idx], sz1 = sz[idx];
        idx++;
        idx = dfs(idx);
        int ql2 = ql[idx], qr2 = qr[idx], sz2 = sz[idx];
        idx++;
        sz[idx] = sz1+sz2;
        if(num){
            ql[idx] = ql1+ql2+1;
            qr[idx] = max(sz1+qr2, sz2+qr1);
        } else{
            ql[idx] = min(ql1, ql2);
            qr[idx] = qr1+qr2;
        }
        return idx;
    }
     
    int main(int argc, const char * argv[]){
        cin.tie(0)->sync_with_stdio(0);
        cin.exceptions(cin.failbit);
        cin >> s;
        int x = dfs(0);
        cout << qr[x]-ql[x]+1 << '\n';
        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...