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

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
using namespace std;
#define FOR(k, m, n) for (int(k) = (m); (k) < (n); (k)++)
#define rep(i, n) FOR((i), 0, (n))
#define N_MAX 100001
#define ll long long

// DP
int stepData[N_MAX];

//?????¨????????´???
int step = 1;
queue<int> nowStep;
queue<int> nowStep2;
stack<int> nextStep;

//???????????¨??????
int N;
int p[N_MAX];

int main() {
  //??\\?????¨?????????
  cin >> N;
  rep(i, N) stepData[i] = -1;
  rep(i, N) cin >> p[i];
  nowStep.push(0);

  //????????????????????§?????????
  while (stepData[N - 1] == -1) {
    //??¨????????????6?????\\???????????¨?????´??????
    while (nowStep.size() > 0) {
      //?????¨?????´???
      int here = nowStep.front();
      // cout<<"a: "<<here<<endl;
      FOR(i, 1, 7) {
        if (here + i < N)
          nowStep2.push(here + i);
      }
      nowStep.pop();
    }

    //??????????????????????????§????????¨???????????????
    while (nowStep2.size() > 0) {
      //?????¨?????´???
      int here = nowStep2.front();

      //????????\\???????????£?????????????°???????????????°?????£??\\?????????
      //??????????????´??????????????°??£??\\
			//??????????????´??????????¬???????????????§p[here]=0??§?????????????¶????
      if (stepData[here] == -1) {
        stepData[here] = step;
        if (p[here] != 0) {
          nowStep2.push(here + p[here]);
          // cout << "b: " << here << endl;
          // cout << "d: " << here+p[here] << endl;
        } else {
          nowStep.push(here);
          // cout << "c: " << here << endl;
        }
      }
      nowStep2.pop();
    }
    step++;
  }

  cout << stepData[N - 1] << endl;
  // cin>>N;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
using namespace std;
#define FOR(k, m, n) for (int(k) = (m); (k) < (n); (k)++)
#define rep(i, n) FOR((i), 0, (n))
#define N_MAX 100001
#define ll long long

// DP
int stepData[N_MAX];

//?????¨????????´???
int step = 1;
queue<int> nowStep;
queue<int> nowStep2;
stack<int> nextStep;

//???????????¨??????
int N;
int p[N_MAX];

int main() {
  //??\\?????¨?????????
  cin >> N;
  rep(i, N) stepData[i] = -1;
  rep(i, N) cin >> p[i];
  nowStep.push(0);

  //????????????????????§?????????
  while (stepData[N - 1] == -1) {
    //??¨????????????6?????\\???????????¨?????´??????
    while (nowStep.size() > 0) {
      //?????¨?????´???
      int here = nowStep.front();
      // cout<<"a: "<<here<<endl;
      FOR(i, 1, 7) nowStep2.push(here + i);
      nowStep.pop();
    }

    //??????????????????????????§????????¨???????????????
    while (nowStep2.size() > 0) {
      //?????¨?????´???
      int here = nowStep2.front();

      //????????\\???????????£?????????????°???????????????°?????£??\\?????????
      //??????????????´??????????????°??£??\\
			//??????????????´??????????¬???????????????§p[here]=0??§?????????????¶????
      if (stepData[here] == -1) {
        stepData[here] = step;
        nowStep2.push(here + p[here]);
        // cout << "b: " << here << endl;
        // cout << "d: " << here+p[here] << endl;

      } else if (p[here] == 0) {
        nowStep.push(here);
        // cout << "c: " << here << endl;
      }
      nowStep2.pop();
    }
    step++;
  }

  cout << stepData[N - 1] << endl;
  // cin>>N;
  return 0;
}