Problem p00069 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
class level {
  int num;
  int size;
  int to_b(const int &n) {
    if (n == 0)
      return 0;
    else
      return (to_b(n / 10) << 1) + (n % 10);
  }

public:
  int test(const int &n) {
    return (((num << (n + 1)) >> size) & 1) - (((num << n) >> size) & 1);
  }
  level(const int &n = 0, const int &d = 0) : size(d) { num = to_b(n); };
};
class Lot {
  std::vector<level> levels;
  std::vector<int> down;
  std::vector<int> up;
  void solve() {
    for (auto i = 0; i < down.size() - 1; ++i) {
      down.at(i + 1) = down.at(i) + levels.at(i).test(down.at(i));
    }
  }
  void solve_inv() {
    for (auto i = up.size() - 1; i > 0; --i) {
      up.at(i - 1) = up.at(i) + levels.at(i - 1).test(up.at(i));
    }
  }

public:
  const int choice;
  const int hit;
  Lot(const int &n, const int &m, const int &h, const int &d)
      : choice(m), hit(h), levels(d), down(d + 1, 0), up(d + 1, 0) {
    for (auto &l : levels) {
      int i;
      std::cin >> i;
      l = level(i, n);
    }
    down.at(0) = m;
    up.at(d) = h;
    solve();
    solve_inv();
  }
  void show() {
    if (down.at(0) == up.at(0)) {
      std::cout << 0 << std::endl;
    } else {
      bool flag = true;
      for (auto i = 0; i < down.size() - 1; ++i) {
        if (((down.at(i) - up.at(i)) * (down.at(i) - up.at(i)) == 1) &&
            (down.at(i) == down.at(i + 1)) && (up.at(i) == up.at(i + 1))) {
          std::cout << i + 1 << " "
                    << ((down.at(i) < up.at(i)) ? down.at(i) : up.at(i))
                    << std::endl;
          i = down.size();
          flag = false;
        }
      }
      if (flag) {
        std::cout << 1 << std::endl;
      }
    }
  }
  void inspect() {
    std::cout << "down" << std::endl;
    for (const auto &d : down) {
      std::cout << d << '\\n';
    }
    std::cout << "up" << std::endl;
    for (const auto &u : up) {
      std::cout << u << '\\n';
    }
  }
};
int main() {
  int n;
  std::cin >> n;
  while (n != 0) {
    int m, h, d;
    std::cin >> m >> h >> d;
    Lot lot(n, m, h, d);
    lot.show();
    std::cin >> n;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
class level {
  int num;
  int size;
  int to_b(const int &n) {
    if (n == 0)
      return 0;
    else
      return (to_b(n / 10) << 1) + (n % 10);
  }

public:
  int test(const int &n) {
    return (((num << (n + 1)) >> size) & 1) - (((num << n) >> size) & 1);
  }
  level(const int &n = 0, const int &d = 0) : size(d) { num = to_b(n); };
};
class Lot {
  std::vector<level> levels;
  std::vector<int> down;
  std::vector<int> up;
  void solve() {
    for (auto i = 0; i < down.size() - 1; ++i) {
      down.at(i + 1) = down.at(i) + levels.at(i).test(down.at(i));
    }
  }
  void solve_inv() {
    for (auto i = up.size() - 1; i > 0; --i) {
      up.at(i - 1) = up.at(i) + levels.at(i - 1).test(up.at(i));
    }
  }

public:
  const int choice;
  const int hit;
  Lot(const int &n, const int &m, const int &h, const int &d)
      : choice(m), hit(h), levels(d), down(d + 1, 0), up(d + 1, 0) {
    for (auto &l : levels) {
      int i;
      std::cin >> i;
      l = level(i, n);
    }
    down.at(0) = m;
    up.at(d) = h;
    solve();
    solve_inv();
  }
  void show() {
    if (down.at(0) == up.at(0)) {
      std::cout << 0 << std::endl;
    } else {
      bool flag = true;
      for (auto i = 0; i < down.size(); ++i) {
        if ((down.at(i) - up.at(i)) * (down.at(i) - up.at(i)) == 1) {
          if ((levels.at(i).test(down.at(i)) == 0) &&
              (levels.at(i).test(up.at(i)) == 0)) {
            std::cout << i + 1 << " "
                      << ((down.at(i) < up.at(i)) ? down.at(i) : up.at(i))
                      << std::endl;
            i = down.size();
            flag = false;
          }
        }
      }
      if (flag) {
        std::cout << 1 << std::endl;
      }
    }
  }
  void inspect() {
    std::cout << "down" << std::endl;
    for (const auto &d : down) {
      std::cout << d << '\\n';
    }
    std::cout << "up" << std::endl;
    for (const auto &u : up) {
      std::cout << u << '\\n';
    }
  }
};
int main() {
  int n;
  std::cin >> n;
  while (n != 0) {
    int m, h, d;
    std::cin >> m >> h >> d;
    Lot lot(n, m, h, d);
    lot.show();
    std::cin >> n;
  }
  return 0;
}