#include <iostream>
#include <vector>
#include <string>
using namespace std;
int N, iter;
string A;
struct R{
int i;
int j;
int n;
};
R load() {
if (A[iter] == '?') {
iter++;
return R{0, 1, 1};
} else if (A[iter + 1] == 'i') {
iter += 4;
R a = load();
iter++;
R b = load();
iter++;
// cout << "MIN = " << min(a.i, b.i) << a.j + b.j - 1 << a.n + b.n << endl;
return R{min(a.i, b.i), a.j + b.j - 1, a.n + b.n};
} else {
iter += 4;
R a = load();
iter++;
R b = load();
iter++;
// cout << "MAX = " << a.i + b.i + 1 << a.n + b.n - min(a.n - a.j, b.n - b.j) << a.n + b.n << endl;
return R{a.i + b.i + 1, a.n + b.n - min(a.n - a.j, b.n - b.j), a.n + b.n};
}
// return R{0, 0, 0};
}
int main() {
cin >> A;
N = 0;
for (char x: A) {
if (x == '?') {
N++;
}
}
iter = 0;
R result = load();
cout << result.j - result.i << endl;
return 0;
}
# | 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... |