This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |