제출 #1323947

#제출 시각아이디문제언어결과실행 시간메모리
1323947itslqHomework (CEOI22_homework)C++20
100 / 100
204 ms123552 KiB
#include "bits/stdc++.h"
// #include <bits/stdc++.h>
using namespace std;

int ind = 0, N = 0;
string S;

struct node {
    node *lc, *rc;
    int op = 0, l, r, sz = 0;                                 // 0 = ?, 1 = min, 2 = max

    node() {
        if (S[ind] == 'm') {
            op = (S[++ind] == 'i') ? 1 : 2;
            ind += 3;
            lc = new node();
            rc = new node();

            sz += lc -> sz;
            sz += rc -> sz;
            ind++;
        } else {
            N++;
            sz = 1;
            ind += 2;
        }
    }

    void solve() {
        if (op == 0) {
            l = 1;
            r = 1;
            return;
        }
        
        lc -> solve();
        rc -> solve();

        if (op == 1) {
            l = min(lc -> l, rc -> l);
            r = lc -> r + rc -> r - 1;
        } else {
            l = lc -> l + rc -> l;
            r = lc -> sz + rc -> sz - min(lc -> sz - lc -> r, rc -> sz - rc -> r);
        }
    }
} *root;

int main() {
    cin >> S;
    root = new node();
    root -> solve();
    cout << (root -> r) - (root -> l) + 1;
}
#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...