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

#include "bits/stdc++.h"
using namespace std;
using namespace std::chrono;
typedef long long ll;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) _repi(i, 0, n)
#define _repi(i, a, b) for (ll i = a; i < b; ++i)
#define rep(...) _overload3(__VA_ARGS__, _repi, _rep)(__VA_ARGS__)
#define _rrepi(i, a, b) for (ll i = b - 1; i >= a; i--)
#define _rrep(i, n) _rrepi(i, 0, n)
#define rrep(...) _overload3(__VA_ARGS__, _rrepi, _rrep)(__VA_ARGS__)
#define sum(...) accumulate(range(__VA_ARGS__), 0)
#define _range(i) (i).begin(), (i).end()
#define _rangek(i, k) (i).begin(), (i).begin() + k
#define range(...) _overload3(__VA_ARGS__, a, _rangek, _range)(__VA_ARGS__)
const ll LINF = 1000000000000000000;
const int INF = 100000007;
const ll MOD = 100000007;
#define Yes(i) out((i) ? "Yes" : "No")
#define vec(type, name, size) vector<type> name(size);
#define VEC(type, name, size)                                                  \\
  vector<type> name(size);                                                     \\
  in(name)
#define INT(...)                                                               \\
  int __VA_ARGS__;                                                             \\
  in(__VA_ARGS__)
#define LL(i)                                                                  \\
  ll i;                                                                        \\
  in(i)
#define STR(i)                                                                 \\
  string i;                                                                    \\
  in(i)
#define CHR(i)                                                                 \\
  char i;                                                                      \\
  in(i)
#define DBL(i)                                                                 \\
  double i;                                                                    \\
  in(i)
struct aaa {
  aaa() {
    cin.tie(0);
    cout << fixed << setprecision(15);
  };
} aaaaaaa;
template <typename T> istream &operator>>(istream &is, vector<T> &vec);
template <typename T, typename L>
istream &operator>>(istream &is, pair<T, L> &p);
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec);
template <typename T, typename L>
ostream &operator<<(ostream &os, pair<T, L> &p);
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}
template <typename T, typename L>
istream &operator>>(istream &is, pair<T, L> &p) {
  is >> p.first;
  is >> p.second;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  rep(i, vec.size()) { os << vec[i] << (i + 1 == vec.size() ? "" : " "); }
  return os;
}
template <typename T, typename L>
ostream &operator<<(ostream &os, pair<T, L> &p) {
  os << p.first << " " << p.second;
  return os;
}
inline void in() {}
inline void in(int &&a) { scanf("%d", &a); }
inline void in(ll &&a) { scanf("%lld", &a); }
inline void in(double &&a) { scanf("%lf", &a); }
inline void in(char &&a) { scanf("%c", &a); }
template <class T> inline void in(T &&a) { cin >> a; }
template <class Head, class... Tail>
inline void in(Head &&head, Tail &&...tail) {
  in(head);
  in(move(tail)...);
}
inline void out() { cout << '\\n'; }
inline void out(const char a[]) {
  if (strcmp(a, "No_Break"))
    cout << a << '\\n';
}
template <class T> inline void out(T a) { cout << a << '\\n'; }
template <class Head, class... Tail> inline void out(Head head, Tail... tail) {
  cout << head << ' ';
  out(move(tail)...);
}
int h, n;
vector<array<int, 4>> s(10001);
vector<vector<vector<vector<int>>>>
    mem(10000, vector<vector<vector<int>>>(
                   2, vector<vector<int>>(2, vector<int>(2, INF))));
int dp(int y, bool a1, bool a2, bool a3) {
  if (y == h)
    return 0;
  if (mem[y][a1][a2][a3] - INF)
    return mem[y][a1][a2][a3];
  int a, max;
  bool b1 = s[y + 2][0] + s[y + 2][1] + s[y + 1][0] + s[y + 1][1],
       b2 = s[y + 2][2] + s[y + 2][1] + s[y + 1][2] + s[y + 1][1],
       b3 = s[y + 2][2] + s[y + 2][3] + s[y + 1][2] + s[y + 1][3];
  max = dp(y + 1, b1, b2, b3);
  if (!a1) {
    a = dp(y + 1, 1, 1, b3) + 1;
    if (max < a)
      max = a;
  }
  if (!a2) {
    a = dp(y + 1, 1, 1, 1) + 1;
    if (max < a)
      max = a;
  }
  if (!a3) {
    a = dp(y + 1, b1, 1, 1) + 1;
    if (max < a)
      max = a;
  }
  if (!(a1 + a3)) {
    a = dp(y + 1, 1, 1, 1) + 2;
    if (max < a)
      max = a;
  }
  mem[y][a1][a2][a3] = max;
  return mem[y][a1][a2][a3];
}
int main() {
  in(h, n);
  rep(i, n) {
    INT(x, y);
    s[y][x] = 1;
  }
  rep(i, 4) s[h][i] = 1;
  out(dp(0, s[0][0] + s[0][1] + s[1][0] + s[1][1],
         s[0][2] + s[0][1] + s[1][2] + s[1][1],
         s[0][2] + s[0][3] + s[1][2] + s[1][3]));
}


Error: 0
....
#...
.#..
...#
....


Fixed submission:

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _overload4(_1, _2, _3, _4, name, ...) name
#define _overload3(_1, _2, _3, name, ...) name
#define _overload2(_1, _2, name, ...) name
#define _re(n) _rep(i, n)
#define _rep(i, n) _repi(i, 0, n)
#define _repi(i, a, b) for (ll i = a; i < b; ++i)
#define _repc(i, a, b, c) for (ll i = a; i < b; i += c)
#define rep(...) _overload4(__VA_ARGS__, _repc, _repi, _rep, _re)(__VA_ARGS__)
#define _rre(n) _rrep(i, n)
#define _rrep(i, n) _rrepi(i, 0, n)
#define _rrepi(i, a, b) for (ll i = b - 1; i >= a; i--)
#define _rrepc(i, a, b, c) for (ll i = a + (b - a - 1) / c * c; i >= a; i -= c)
#define rrep(...)                                                              \\
  _overload4(__VA_ARGS__, _rrepc, _rrepi, _rrep, _rre)(__VA_ARGS__)
#define sum(...) accumulate(range(__VA_ARGS__), 0)
#define _range(i) (i).begin(), (i).end()
#define _rangek(i, k) (i).begin(), (i).begin() + k
#define range(...) _overload2(__VA_ARGS__, _rangek, _range)(__VA_ARGS__)
#define LINF (ll)1000000000000000000
#define MOD (ll)1000000007
#define INF (int)1000000007
#define Yes(i) out(i ? "Yes" : "No")
#define YES(i) out(i ? "YES" : "NO")
#define INT(...)                                                               \\
  int __VA_ARGS__;                                                             \\
  in(__VA_ARGS__)
#define LL(...)                                                                \\
  ll __VA_ARGS__;                                                              \\
  in(__VA_ARGS__)
#define STR(...)                                                               \\
  string __VA_ARGS__;                                                          \\
  in(__VA_ARGS__)
#define CHR(...)                                                               \\
  char __VA_ARGS__;                                                            \\
  in(__VA_ARGS__)
#define DBL(...)                                                               \\
  double __VA_ARGS__;                                                          \\
  in(__VA_ARGS__)
#define vec(type, name, size) vector<type> name(size);
#define VEC(type, name, size)                                                  \\
  vector<type> name(size);                                                     \\
  in(name)
struct aaa {
  aaa() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  };
} aaaaaaa;
inline void in() {}
template <typename T> istream &operator>>(istream &is, vector<T> &vec);
template <typename T, typename L>
istream &operator>>(istream &is, pair<T, L> &p);
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec);
template <typename T, typename L>
ostream &operator<<(ostream &os, pair<T, L> &p);
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}
template <typename T, typename L>
istream &operator>>(istream &is, pair<T, L> &p) {
  is >> p.first;
  is >> p.second;
  return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << vec[0];
  rep(i, 1, vec.size()) { os << ' ' << vec[i]; }
  return os;
}
template <typename T, typename L>
ostream &operator<<(ostream &os, pair<T, L> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <class Head, class... Tail>
inline void in(Head &&head, Tail &&...tail) {
  cin >> head;
  in(move(tail)...);
}
template <class T> inline void out(T t) { cout << t << '\\n'; }
inline void out() { cout << '\\n'; }
template <class Head, class... Tail> inline void out(Head head, Tail... tail) {
  cout << head << ' ';
  out(move(tail)...);
}

int main() {
  INT(h, n);
  vector<vector<bool>> a(4, vector<bool>(h));
  rep(n) {
    INT(x, y);
    a[x][y] = 1;
  }
  rep(h) {
    rep(j, 4) cerr << (a[j][i] ? '#' : '.');
    cerr << endl;
  }
  int ans = 0;
  rep(j,
      h - 1) if (!a[0][j] && !a[0 + 1][j] && !a[0][j + 1] && !a[0 + 1][j + 1]) {
    a[0][j] = a[0 + 1][j] = a[0][j + 1] = a[0 + 1][j + 1] = 1;
    ans++;
  }
  rep(j,
      h - 1) if (!a[2][j] && !a[2 + 1][j] && !a[2][j + 1] && !a[2 + 1][j + 1]) {
    a[2][j] = a[2 + 1][j] = a[2][j + 1] = a[2 + 1][j + 1] = 1;
    ans++;
  }
  rep(j,
      h - 1) if (!a[1][j] && !a[1 + 1][j] && !a[1][j + 1] && !a[1 + 1][j + 1]) {
    a[1][j] = a[1 + 1][j] = a[1][j + 1] = a[1 + 1][j + 1] = 1;
    ans++;
  }
  out(ans);
}