123456789101112131415161718192021222324 |
- #include <iostream>
- #include <cstdio>
- #include <cstdint>
- #include <string>
- #include <vector>
- using namespace std;
- bool recurse(vector<int> tree, int root, int min, int max);
- int main() {
- vector<int> tree(1);
- string tmp;
- while (getline(cin, tmp, ',')) tree.push_back(stoi(tmp));
- if (recurse(tree, 1, INT32_MIN, INT32_MAX)) printf("True\n");
- else printf("False\n");
- return 0;
- }
- bool recurse(vector<int> tree, int root, int min, int max) {
- if (tree.size() <= root) return true;
- if (tree[root] <= min || max <= tree[root]) return false;
- return recurse(tree, root*2, min, tree[root]) && recurse(tree, root*2+1, tree[root], max);
- }
|