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

#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

bool b[103][52][103][52] = {};

int main() {

  while (true) {

    long long int w, h;
    cin >> w >> h;

    if (w == 0)
      break;

    vector<string> map;

    map.push_back("############################################################"
                  "##################################################");

    long long int rx, ry, lx, ly;

    for (long long int y = 1; y <= h; y++) {

      string in_L, in_R;
      cin >> in_L >> in_R;

      string in = "#" + in_L + "#" + in_R + "#";
      map.push_back(in);

      for (long long int x = 0; x < in.size(); x++) {

        if (map[y][x] == 'R') {
          rx = x;
          ry = y;
        }
        if (map[y][x] == 'L') {
          lx = x;
          ly = y;
        }
      }
    }

    map.push_back("############################################################"
                  "##################################################");

    for (long long int y = 0; y < map.size(); y++) {
      for (long long int x = 0; x < map[1].size(); x++) {
        for (long long int y2 = 0; y2 < map.size(); y2++) {
          for (long long int x2 = 0; x2 < map[1].size(); x2++) {
            b[x][y][x2][y2] = false;
          }
        }
      }
    }

    queue<vector<long long int>> q;
    vector<long long int> v;
    v.push_back(rx);
    v.push_back(ry);
    v.push_back(lx);
    v.push_back(ly);
    q.push(v);

    bool ans = false;

    while (q.size() > 0) {

      rx = q.front()[0];
      ry = q.front()[1];
      lx = q.front()[2];
      ly = q.front()[3];
      q.pop();

      //      cout << rx << " " << ry << " " << lx << " " << ly << endl;

      if (b[rx][ry][lx][ly] == true)
        continue;

      b[rx][ry][lx][ly] = true;

      if (map[ry][rx] == '%' && map[ly][lx] == '%') {
        cout << "Yes" << endl;
        ans = true;
        break;
      } else if (map[ry][rx] == '%') {
        continue;
      } else if (map[ly][lx] == '%') {
        continue;
      }

      v.clear();
      if (map[ry][rx + 1] == '#') {
        v.push_back(rx);
      } else {
        v.push_back(rx + 1);
      }
      v.push_back(ry);
      if (map[ly][lx - 1] == '#') {
        v.push_back(lx);
      } else {
        v.push_back(lx - 1);
      }
      v.push_back(ly);
      q.push(v);

      v.clear();
      v.push_back(rx);
      if (map[ry - 1][rx] == '#') {
        v.push_back(ry);
      } else {
        v.push_back(ry - 1);
      }
      v.push_back(lx);
      if (map[ly - 1][lx] == '#') {
        v.push_back(ly);
      } else {
        v.push_back(ly - 1);
      }
      q.push(v);

      v.clear();
      if (map[ry][rx - 1] == '#') {
        v.push_back(rx);
      } else {
        v.push_back(rx - 1);
      }
      v.push_back(ry);
      if (map[ly][lx + 1] == '#') {
        v.push_back(lx);
      } else {
        v.push_back(lx + 1);
      }
      v.push_back(ly);
      q.push(v);

      v.clear();
      v.push_back(rx);
      if (map[ry + 1][rx] == '#') {
        v.push_back(ry);
      } else {
        v.push_back(ry + 1);
      }
      v.push_back(lx);
      if (map[ly + 1][lx] == '#') {
        v.push_back(ly);
      } else {
        v.push_back(ly + 1);
      }
      q.push(v);
    }

    if (ans == false) {
      cout << "No" << endl;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

bool b[103][52][103][52] = {};

int main() {

  while (true) {

    long long int w, h;
    cin >> w >> h;

    if (w == 0)
      break;

    vector<string> map;

    map.push_back("############################################################"
                  "##################################################");

    long long int rx, ry, lx, ly;

    for (long long int y = 1; y <= h; y++) {

      string in_L, in_R;
      cin >> in_L >> in_R;

      string in = "#" + in_L + "#" + in_R + "#";
      map.push_back(in);

      for (long long int x = 0; x < in.size(); x++) {

        if (map[y][x] == 'R') {
          rx = x;
          ry = y;
        }
        if (map[y][x] == 'L') {
          lx = x;
          ly = y;
        }
      }
    }

    map.push_back("############################################################"
                  "##################################################");

    for (long long int y = 0; y < map.size(); y++) {
      for (long long int x = 0; x < map[0].size(); x++) {
        for (long long int y2 = 0; y2 < map.size(); y2++) {
          for (long long int x2 = 0; x2 < map[0].size(); x2++) {
            b[x][y][x2][y2] = false;
          }
        }
      }
    }

    queue<vector<long long int>> q;
    vector<long long int> v;
    v.push_back(rx);
    v.push_back(ry);
    v.push_back(lx);
    v.push_back(ly);
    q.push(v);

    bool ans = false;

    while (q.size() > 0) {

      rx = q.front()[0];
      ry = q.front()[1];
      lx = q.front()[2];
      ly = q.front()[3];
      q.pop();

      if (b[rx][ry][lx][ly] == true)
        continue;

      b[rx][ry][lx][ly] = true;

      if (map[ry][rx] == '%' && map[ly][lx] == '%') {
        cout << "Yes" << endl;
        ans = true;
        break;
      } else if (map[ry][rx] == '%') {
        continue;
      } else if (map[ly][lx] == '%') {
        continue;
      }

      //      cout << rx << " " << ry << " " << lx << " " << ly << endl;

      v.clear();
      if (map[ry][rx + 1] == '#') {
        v.push_back(rx);
      } else {
        v.push_back(rx + 1);
      }
      v.push_back(ry);
      if (map[ly][lx - 1] == '#') {
        v.push_back(lx);
      } else {
        v.push_back(lx - 1);
      }
      v.push_back(ly);
      q.push(v);

      v.clear();
      v.push_back(rx);
      if (map[ry - 1][rx] == '#') {
        v.push_back(ry);
      } else {
        v.push_back(ry - 1);
      }
      v.push_back(lx);
      if (map[ly - 1][lx] == '#') {
        v.push_back(ly);
      } else {
        v.push_back(ly - 1);
      }
      q.push(v);

      v.clear();
      if (map[ry][rx - 1] == '#') {
        v.push_back(rx);
      } else {
        v.push_back(rx - 1);
      }
      v.push_back(ry);
      if (map[ly][lx + 1] == '#') {
        v.push_back(lx);
      } else {
        v.push_back(lx + 1);
      }
      v.push_back(ly);
      q.push(v);

      v.clear();
      v.push_back(rx);
      if (map[ry + 1][rx] == '#') {
        v.push_back(ry);
      } else {
        v.push_back(ry + 1);
      }
      v.push_back(lx);
      if (map[ly + 1][lx] == '#') {
        v.push_back(ly);
      } else {
        v.push_back(ly + 1);
      }
      q.push(v);
    }

    if (ans == false) {
      cout << "No" << endl;
    }
  }

  return 0;
}