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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <vector>

using namespace std;

#define int long long

list<bool *> fld;

list<bool *>::iterator GetHeight(int l, int r) {
  list<bool *>::iterator itr = fld.begin();
  // fld.push_front((bool*)new bool[5]{});
  for (; itr != fld.end(); itr++) {
    for (int i = l; i < r; i++) {
      if ((*itr)[i] == true)
        return --itr;
    }
  }
  return --itr;
}

void PushFront() {
  fld.push_front((bool *)new bool[5]);
  for (int i = 0; i < 5; i++) {
    (*fld.begin())[i] = false;
  }
}

bool IsFull(list<bool *>::iterator itr) {
  for (int i = 0; i < 5; i++) {
    if ((*itr)[i] == false)
      return false;
  }
  return true;
}

bool IsEmpty(list<bool *>::iterator itr) {
  for (int i = 0; i < 5; i++) {
    if ((*itr)[i] == true)
      return false;
  }
  return true;
}

void Drop(int d, int p, int q) {
  if (!IsEmpty(fld.begin()))
    PushFront();
  int l = q - 1, r = (d == 1) ? l + p : l + 1;
  list<bool *>::iterator itr = GetHeight(l, r);

  int h = (d == 1) ? 1 : p;
  for (int i = 0; i < h; i++) {
    if (itr == fld.begin())
      PushFront();
    for (int j = l; j < r; j++) {
      (*itr)[j] = true;
    }
    if (IsFull(itr)) {
      delete *itr;
      itr = fld.erase(itr);
    }
    itr--;
  }
}

signed main() {
  int N;
  while (cin >> N, N) {
    fld.clear();
    PushFront();
    for (int i = 0; i < N; i++) {
      int d, p, q;
      cin >> d >> p >> q;
      Drop(d, p, q);
    }
    int ans = 0;
    for (list<bool *>::iterator itr = fld.begin(); itr != fld.end(); itr++) {
      for (int i = 0; i < 5; i++) {
        ans += ((*itr)[i] == true);
      }
    }
    printf("%lld\\n", ans);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <vector>

using namespace std;

#define int long long

list<bool *> fld;

list<bool *>::iterator GetHeight(int l, int r) {
  list<bool *>::iterator itr = fld.begin();
  // fld.push_front((bool*)new bool[5]{});
  for (; itr != fld.end(); itr++) {
    for (int j = l; j < r; j++) {
      if ((*itr)[j] == true)
        return --itr;
    }
  }
  return --itr;
}

bool IsFull(list<bool *>::iterator itr) {
  for (int i = 0; i < 5; i++) {
    if ((*itr)[i] == false)
      return false;
  }
  return true;
}

bool IsEmpty(list<bool *>::iterator itr) {
  for (int i = 0; i < 5; i++) {
    if ((*itr)[i] == true)
      return false;
  }
  return true;
}

void Drop(int d, int p, int q) {
  if (!IsEmpty(fld.begin()))
    fld.push_front((bool *)new bool[5]{});
  int l = q - 1, r = (d == 1) ? l + p : l + 1;
  list<bool *>::iterator itr = GetHeight(l, r);

  int h = (d == 1) ? 1 : p;
  for (int i = 0; i < h; i++) {
    if (itr == fld.begin())
      fld.push_front((bool *)new bool[5]{});
    for (int j = l; j < r; j++) {
      (*itr)[j] = true;
    }
    if (IsFull(itr)) {
      delete *itr;
      itr = fld.erase(itr);
    }
    itr--;
  }
}

signed main() {
  int N;
  while (cin >> N, N) {
    fld.clear();
    fld.push_back((bool *)new bool[5]{});
    for (int i = 0; i < N; i++) {
      int d, p, q;
      cin >> d >> p >> q;
      Drop(d, p, q);
    }
    int ans = 0;
    for (list<bool *>::iterator itr = fld.begin(); itr != fld.end(); itr++) {
      for (int i = 0; i < 5; i++) {
        ans += ((*itr)[i] == true);
      }
    }
    printf("%lld\\n", ans);
  }
  return 0;
}