main.cpp 665 B

123456789101112131415161718192021222324
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdint>
  4. #include <string>
  5. #include <vector>
  6. using namespace std;
  7. bool recurse(vector<int> tree, int root, int min, int max);
  8. int main() {
  9. vector<int> tree(1);
  10. string tmp;
  11. while (getline(cin, tmp, ',')) tree.push_back(stoi(tmp));
  12. if (recurse(tree, 1, INT32_MIN, INT32_MAX)) printf("True\n");
  13. else printf("False\n");
  14. return 0;
  15. }
  16. bool recurse(vector<int> tree, int root, int min, int max) {
  17. if (tree.size() <= root) return true;
  18. if (tree[root] <= min || max <= tree[root]) return false;
  19. return recurse(tree, root*2, min, tree[root]) && recurse(tree, root*2+1, tree[root], max);
  20. }