#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
struct ans {
int l, r, size;
};
auto solve = [&](auto &&self) -> ans {
char ch;
std::cin >> ch;
if (ch == '?') {
std::cin >> ch;
return {1, 1, 1};
}
std::cin >> ch;
bool is_max = ch == 'a';
std::cin >> ch >> ch;
ans left = self(self);
ans right = self(self);
ans res;
if (is_max) {
res.l = left.l + right.l;
res.r = std::max(left.size + right.r, right.size + left.r);
} else {
res.l = std::min(left.l, right.l);
res.r = left.r + right.r - 1;
}
res.size = left.size + right.size;
std::cin >> ch;
return res;
};
ans res = solve(solve);
std::cout << res.r - res.l + 1 << '\n';
}
# | 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... |