제출 #968643

#제출 시각아이디문제언어결과실행 시간메모리
968643tsetHomework (CEOI22_homework)C++14
100 / 100
400 ms151204 KiB
#include<bits/stdc++.h>

using namespace std;

#define int long long
#define pii pair<int, int>

const int INF = 1e18 +42;

struct Noeud
{
    int type, l, r;
};

vector<Noeud> noeuds;
int N = 0;

pii getAns(int nde)
{
    if(noeuds[nde].type == 0)
        return {1, 1};
    pii ansLeft = getAns(noeuds[nde].l);
    pii ansRight = getAns(noeuds[nde].r);
    if(noeuds[nde].type == 1)
        return {ansLeft.first + ansRight.first, min(ansLeft.second, ansRight.second)};
    return {min(ansLeft.first, ansRight.first), ansLeft.second + ansRight.second};
}


int parse()
{
    char car, useless;
    cin >> car;
    if(car == '?')
    {
        int id = noeuds.size();
        noeuds.push_back({0, -1, -1});
        N++;
        return id;        
    }
    cin >> car;
    cin >> car;
    cin >> useless;
    int l = parse();
    cin >> useless;
    int r = parse();
    cin >> useless;
    int id = noeuds.size();
    if(car == 'x')
        noeuds.push_back({1, l, r});
    else
        noeuds.push_back({-1, l, r});
    return id;
}

signed main()
{
    int rootNode = parse();
    pii ans = getAns(rootNode);
    cout << max(1ll, N - ans.first - ans.second +2) << endl;
}
#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...