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

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.txt"

int fall(vector<vector<int>> &field, vector<vector<int>> &pino, int l) {
  {}
  int y = 0;
  for (y = 0; y < field.size() - pino.size(); ++y) {
    bool ok = true;
    for (int i = 0; i < pino.size(); ++i) {
      for (int j = 0; j < pino[i].size(); ++j) {
        if (pino[i][j]) {
          if (field[y + i + 1][l + j])
            ok = false;
        }
      }
    }
    if (!ok) {
      break;
    }
  }
  for (int i = 0; i < pino.size(); ++i) {
    for (int j = 0; j < pino[i].size(); ++j) {
      if (pino[i][j]) {
        assert(!field[y + i][l + j]);
        field[y + i][l + j] = true;
      }
    }
  }
  int delline = 0;
  for (int i = y + pino.size() - 1; i >= y; --i) {
    while (all_of(field[i].begin(), field[i].end(),
                  [](const int a) { return a == 1; })) {
      transform(field[i].begin(), field[i].end(), field[i].begin(),
                [](const int a) { return false; });
      for (int j = i - 1; j >= 0; --j) {
        swap(field[j], field[j + 1]);
      }
      delline += 1;
    }
  }
  return delline;
}

int main() {
  while (1) {
    int N;
    cin >> N;
    if (!N)
      break;
    int sum = 0;
    vector<vector<int>> field(5 * N + 10, vector<int>(5));
    for (int i = 0; i < N; ++i) {
      int d, p, q;
      cin >> d >> p >> q;
      q--;
      int w = d == 2 ? 1 : p;
      int h = d == 1 ? 1 : p;
      sum += p;
      vector<vector<int>> pino(h, vector<int>(w, 1));
      sum -= fall(field, pino, q) * 5;
    }
    cout << sum << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.txt"

int fall(vector<vector<int>> &field, vector<vector<int>> &pino, int l) {
  {}
  int y = 0;
  for (y = 0; y < field.size() - pino.size(); ++y) {
    bool ok = true;
    for (int i = 0; i < pino.size(); ++i) {
      for (int j = 0; j < pino[i].size(); ++j) {
        if (pino[i][j]) {
          if (field[y + i + 1][l + j])
            ok = false;
        }
      }
    }
    if (!ok) {
      break;
    }
  }
  for (int i = 0; i < pino.size(); ++i) {
    for (int j = 0; j < pino[i].size(); ++j) {
      if (pino[i][j]) {
        assert(!field[y + i][l + j]);
        field[y + i][l + j] = true;
      }
    }
  }
  int delline = 0;
  for (int i = y + pino.size() - 1; i >= y; --i) {
    while (all_of(field[i].begin(), field[i].end(),
                  [](const int a) { return a == 1; })) {
      transform(field[i].begin(), field[i].end(), field[i].begin(),
                [](const int a) { return false; });
      for (int j = i - 1; j >= 0; --j) {
        swap(field[j], field[j + 1]);
      }
      delline += 1;
    }
  }
  return delline;
}

int main() {
  while (1) {
    int N;
    cin >> N;
    if (!N)
      break;
    int sum = 0;
    vector<vector<int>> field(10, vector<int>(5));
    for (int i = 0; i < N; ++i) {
      int d, p, q;
      cin >> d >> p >> q;
      q--;
      int w = d == 2 ? 1 : p;
      int h = d == 1 ? 1 : p;
      sum += p;
      vector<vector<int>> pino(h, vector<int>(w, 1));
      sum -= fall(field, pino, q) * 5;
    }
    cout << sum << endl;
  }

  return 0;
}