Problem p00230 (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"

struct aa {
  int y;
  int x;
  int time;
};

int main() {
  while (1) {
    int N;
    cin >> N;
    if (!N)
      break;
    vector<vector<int>> walls(N, vector<int>(2));
    vector<vector<int>> memo(N, vector<int>(2, 10000));
    for (int y = 0; y < 2; ++y) {
      for (int i = 0; i < N; ++i) {
        cin >> walls[i][y];
      }
    }
    queue<aa> que;
    memo[0][0] = 0;
    que.push(aa{0, 0, 0});
    que.push(aa{0, 1, 0});
    memo[0][1] = 0;
    int ans = -1;
    while (!que.empty()) {
      auto atop(que.front());
      que.pop();
      if (atop.y == N - 1) {
        ans = atop.time;
        break;
      }
      while (walls[atop.y][atop.x] == 1 && walls[atop.y + 1][atop.x] == 1) {
        atop.y++;
        if (atop.y == N - 1) {
          ans = atop.time;
          break;
        }
      }
      if (atop.y == N - 1) {
        ans = atop.time;
        break;
      }
      for (int dy = 0; dy <= 2; ++dy) {
        int ny = atop.y + dy;
        if (ny >= N)
          continue;
        int nx = !atop.x;
        while (walls[ny][nx] == 2) {
          ny--;
        }
        if (memo[ny][nx] > atop.time + 1) {
          memo[ny][nx] = atop.time + 1;
          que.push(aa{ny, nx, atop.time + 1});
        }
      }
    }
    if (ans == -1)
      cout << "NA" << endl;
    else
      cout << ans << 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"

struct aa {
  int y;
  int x;
  int time;
};

int main() {
  while (1) {
    int N;
    cin >> N;
    if (!N)
      break;
    vector<vector<int>> walls(N, vector<int>(2));
    vector<vector<int>> memo(N, vector<int>(2, 10000));
    for (int y = 0; y < 2; ++y) {
      for (int i = 0; i < N; ++i) {
        cin >> walls[i][y];
      }
    }
    queue<aa> que;
    memo[0][0] = 0;
    que.push(aa{0, 0, 0});
    que.push(aa{0, 1, 0});
    memo[0][1] = 0;
    int ans = -1;
    while (!que.empty()) {
      auto atop(que.front());
      que.pop();
      if (atop.y == N - 1) {
        ans = atop.time;
        break;
      }
      for (int dy = 0; dy <= 2; ++dy) {
        int ny = atop.y + dy;
        if (ny >= 8)
          continue;
        int nx = !atop.x;
        while (walls[ny][nx] == 2) {
          ny--;
        }
        while (ny != N - 1 && walls[ny][nx] == 1 && walls[ny + 1][nx] == 1) {
          ny++;
        }
        if (memo[ny][nx] > atop.time + 1) {
          memo[ny][nx] = atop.time + 1;
          que.push(aa{ny, nx, atop.time + 1});
        }
      }
    }
    if (ans == -1)
      cout << "NA" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}