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

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int gx, gy;
    cin >> gx >> gy;
    int vert[gx + 2][gy + 2], horiz[gx + 2][gy + 2];
    int k;
    cin >> k;
    for (int i = 0; i < gx + 2; i++) {
      for (int j = 0; j < gy + 2; j++) {
        if (i == 0 || j == 0) {
          vert[i][j] = 0;
          horiz[i][j] = 0;
        } else {
          vert[i][j] = 1;
          horiz[i][j] = 1;
        }
      }
    }
    for (int i = 0; i < k; i++) {
      int mxs, mys, mxg, myg;
      cin >> mxs >> mys >> mxg >> myg;
      if (mxs == mxg && mys > myg) {
        horiz[mxs + 1][mys + 1] = 0;
      } else if (mxs == mxg && mys < myg) {
        horiz[mxg + 1][myg + 1] = 0;
      }
      if (mys == myg && mxs > mxg) {
        vert[mxs + 1][mys + 1] = 0;
      } else if (mys == myg && mxs < mxg) {
        vert[mxg + 1][myg + 1] = 0;
      }
    }
    // debug
    /*
     for(int j = 0; j < gy+2; j++){
         for(int i = 0; i < gx+2; i++){
            cout << vert[i][j] << horiz[i][j] << " ";
         }
         cout << "\\n";
    }
    */
    int hmap[gx + 2][gy + 2];
    for (int i = 0; i < gx + 2; i++) {
      for (int j = 0; j < gy + 2; j++) {
        hmap[i][j] = 0;
      }
    }
    for (int i = 1; i < gx + 2; i++) {
      for (int j = 1; j < gy + 2; j++) {
        if (i == 1 && j == 1) {
          hmap[i][j] = 1;
        } else {
          if (vert[i][j] && horiz[i][j]) {
            hmap[i][j] = hmap[i - 1][j] + hmap[i][j - 1];
          } else if (!vert[i][j] && horiz[i][j]) {
            hmap[i][j] = hmap[i][j - 1];
          } else if (vert[i][j] && !horiz[i][j]) {
            hmap[i][j] = hmap[i - 1][j];
          } else if (!vert[i][j] && !horiz[i][j]) {
            hmap[i][j] = 0;
          }
        }
      }
    }
    // debug
    /*
    for(int j = 0; j < gy+2; j++){
         for(int i = 0; i < gx+2; i++){
             cout << hmap[i][j] << " ";
         }
         cout << "\\n";
     }
     */

    if (hmap[gx + 1][gy + 1] == 0)
      cout << "Miserable Hokusai!\\n";
    else
      cout << hmap[gx + 1][gy + 1] << "\\n";
  }
}

Error: -11

Fixed submission:

#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int gx, gy;
    cin >> gx >> gy;
    vector<vector<bool>> vert(gx + 2, vector<bool>(gy + 2, true));
    vector<vector<bool>> horiz(gx + 2, vector<bool>(gy + 2, true));
    int k;
    cin >> k;
    for (int i = 0; i < gy + 2; i++) {
      vert[0][i] = false;
      horiz[0][i] = false;
    }
    for (int i = 0; i < gx + 2; i++) {
      vert[i][0] = false;
      horiz[i][0] = false;
    }
    for (int i = 0; i < k; i++) {
      int mxs, mys, mxg, myg;
      cin >> mxs >> mys >> mxg >> myg;
      if (mxs == mxg && mys < myg) {
        vert[mxs + 2][mys + 2] = false;
      } else if (mxs == mxg && mys > myg) {
        vert[mxg + 2][myg + 2] = false;
      }
      if (mys == myg && mxs < mxg) {
        horiz[mxs + 2][mys + 2] = false;
      } else if (mys == myg && mxs > mxg) {
        horiz[mxg + 2][myg + 2] = false;
      }
    }
    // debug
    /*
    for(int i = 0; i < gx+2; i++){
        for(int j = 0; j < gy+2; j++){
            cout << vert[i][j] << horiz[i][j] << " ";
        }
        cout << "\\n";
    }*/

    vector<vector<int>> hmap(gx + 2, vector<int>(gy + 2, 0));
    for (int i = 1; i < gx + 2; i++) {
      for (int j = 1; j < gy + 2; j++) {
        if (i == 1 && j == 1) {
          hmap[i][j] = 1;
        } else {
          if (vert[i][j] && horiz[i][j]) {
            hmap[i][j] = hmap[i - 1][j] + hmap[i][j - 1];
          } else if (!vert[i][j] && horiz[i][j]) {
            hmap[i][j] = hmap[i][j - 1];
          } else if (vert[i][j] && !horiz[i][j]) {
            hmap[i][j] = hmap[i - 1][j];
          } else if (!vert[i][j] && !horiz[i][j]) {
            hmap[i][j] = 0;
          }
        }
      }
    }
    // debug
    /*
for(int i = 0; i < gx+2; i++){
    for(int j = 0; j < gy+2; j++){
        cout << hmap[i][j] << " ";
    }
    cout << "\\n";
}*/

    if (hmap[gx][gy] == 0)
      cout << "Miserable Hokusai!\\n";
    else
      cout << hmap[gx + 1][gy + 1] << "\\n";
  }
}