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

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int H, W;
int ****min_Count;
int diff_row[4] = {-1, 0, 0, 1}, diff_col[4] = {0, -1, 1, 0};

struct Info {
  Info(int arg_L_row, int arg_L_col, int arg_R_row, int arg_R_col,
       int arg_count) {
    L_row = arg_L_row;
    L_col = arg_L_col;
    R_row = arg_R_row;
    R_col = arg_R_col;
    count = arg_count;
  }
  int L_row, L_col, R_row, R_col, count;
};

bool rangeCheck(int row, int col) {
  if (row >= 0 && row <= H - 1 && col >= 0 && col <= W - 1)
    return true;
  else {
    return false;
  }
}

void func() {

  for (int a = 0; a < H; a++) {
    for (int b = 0; b < W; b++) {
      for (int c = 0; c < H; c++) {
        for (int d = 0; d < W; d++)
          min_Count[a][b][c][d] = BIG_NUM;
      }
    }
  }

  char L_map[H][W + 1], R_map[H][W + 1];

  int L_start_row, L_start_col, R_start_row, R_start_col;

  for (int i = 0; i < H; i++) {
    scanf("%s %s", L_map[i], R_map[i]);
    for (int k = 0; k < W; k++) {
      if (L_map[i][k] == 'L') {
        L_start_row = i;
        L_start_col = k;
        L_map[i][k] = '.';
      }
      if (R_map[i][k] == 'R') {
        R_start_row = i;
        R_start_col = k;
        R_map[i][k] = '.';
      }
    }
  }

  queue<Info> Q;
  Q.push(Info(L_start_row, L_start_col, R_start_row, R_start_col, 0));
  min_Count[L_start_row][L_start_col][R_start_row][R_start_col] = 0;

  bool FLG = false;

  int next_L_row, next_L_col, next_R_row, next_R_col;

  while (!Q.empty()) {

    if (L_map[Q.front().L_row][Q.front().L_col] == '%' &&
        R_map[Q.front().R_row][Q.front().R_col] == '%') {
      FLG = true;
      break;
    } else if (Q.front().count > min_Count[Q.front().L_row][Q.front().L_col]
                                          [Q.front().R_row][Q.front().R_col]) {
      Q.pop();
    } else {

      for (int i = 0; i < 4; i++) {
        next_L_row = Q.front().L_row + diff_row[i];
        next_L_col = Q.front().L_col + diff_col[i];
        next_R_row = Q.front().R_row + diff_row[i];
        next_R_col = Q.front().R_col - diff_col[i];

        if (rangeCheck(next_L_row, next_L_col) == false ||
            L_map[next_L_row][next_L_col] == '#') {
          next_L_row = Q.front().L_row;
          next_L_col = Q.front().L_col;
        }
        if (rangeCheck(next_R_row, next_R_col) == false ||
            R_map[next_R_row][next_R_col] == '#') {
          next_R_row = Q.front().R_row;
          next_R_col = Q.front().R_col;
        }

        if (min_Count[next_L_row][next_L_col][next_R_row][next_R_col] >
            Q.front().count + 1) {
          if ((L_map[next_L_row][next_L_col] == '%' &&
               R_map[next_R_row][next_R_col] != '%') ||
              (L_map[next_L_row][next_L_col] != '%' &&
               R_map[next_R_row][next_R_col] == '%')) {
            // Do nothing
          } else {
            min_Count[next_L_row][next_L_col][next_R_row][next_R_col] =
                Q.front().count + 1;
            Q.push(Info(next_L_row, next_L_col, next_R_row, next_R_col,
                        Q.front().count + 1));
          }
        }
      }
      Q.pop();
    }
  }

  if (FLG) {
    printf("Yes\\n");
  } else {
    printf("No\\n");
  }
}

int main() {

  min_Count = new int ***[50];
  ;
  for (int i = 0; i < 50; i++) {
    min_Count[i] = new int **[50];
    for (int k = 0; k < 50; k++) {
      min_Count[i][k] = new int *[50];
      for (int a = 0; a < 50; a++) {
        min_Count[i][k][a] = new int[50];
      }
    }
  }

  while (true) {
    scanf("%d %d", &W, &H);
    if (W == 0 && H == 0)
      break;

    func();
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

int H, W;
int diff_row[4] = {-1, 0, 0, 1}, diff_col[4] = {0, -1, 1, 0};

struct Info {
  Info(int arg_L_row, int arg_L_col, int arg_R_row, int arg_R_col,
       int arg_count) {
    L_row = arg_L_row;
    L_col = arg_L_col;
    R_row = arg_R_row;
    R_col = arg_R_col;
    count = arg_count;
  }
  int L_row, L_col, R_row, R_col, count;
};

bool rangeCheck(int row, int col) {
  if (row >= 0 && row <= H - 1 && col >= 0 && col <= W - 1)
    return true;
  else {
    return false;
  }
}

void func() {

  int min_Count[H][W][H][W];
  for (int a = 0; a < H; a++) {
    for (int b = 0; b < W; b++) {
      for (int c = 0; c < H; c++) {
        for (int d = 0; d < W; d++)
          min_Count[a][b][c][d] = BIG_NUM;
      }
    }
  }

  char L_map[H][W + 1], R_map[H][W + 1];

  int L_start_row, L_start_col, R_start_row, R_start_col;

  for (int i = 0; i < H; i++) {
    scanf("%s %s", L_map[i], R_map[i]);
    for (int k = 0; k < W; k++) {
      if (L_map[i][k] == 'L') {
        L_start_row = i;
        L_start_col = k;
        L_map[i][k] = '.';
      }
      if (R_map[i][k] == 'R') {
        R_start_row = i;
        R_start_col = k;
        R_map[i][k] = '.';
      }
    }
  }

  queue<Info> Q;
  Q.push(Info(L_start_row, L_start_col, R_start_row, R_start_col, 0));
  min_Count[L_start_row][L_start_col][R_start_row][R_start_col] = 0;

  bool FLG = false;

  int next_L_row, next_L_col, next_R_row, next_R_col;

  while (!Q.empty()) {

    if (L_map[Q.front().L_row][Q.front().L_col] == '%' &&
        R_map[Q.front().R_row][Q.front().R_col] == '%') {
      FLG = true;
      break;
    } else if (Q.front().count > min_Count[Q.front().L_row][Q.front().L_col]
                                          [Q.front().R_row][Q.front().R_col]) {
      Q.pop();
    } else {

      for (int i = 0; i < 4; i++) {
        next_L_row = Q.front().L_row + diff_row[i];
        next_L_col = Q.front().L_col + diff_col[i];
        next_R_row = Q.front().R_row + diff_row[i];
        next_R_col = Q.front().R_col - diff_col[i];

        if (rangeCheck(next_L_row, next_L_col) == false ||
            L_map[next_L_row][next_L_col] == '#') {
          next_L_row = Q.front().L_row;
          next_L_col = Q.front().L_col;
        }
        if (rangeCheck(next_R_row, next_R_col) == false ||
            R_map[next_R_row][next_R_col] == '#') {
          next_R_row = Q.front().R_row;
          next_R_col = Q.front().R_col;
        }

        if (min_Count[next_L_row][next_L_col][next_R_row][next_R_col] >
            Q.front().count + 1) {
          if ((L_map[next_L_row][next_L_col] == '%' &&
               R_map[next_R_row][next_R_col] != '%') ||
              (L_map[next_L_row][next_L_col] != '%' &&
               R_map[next_R_row][next_R_col] == '%')) {
            // Do nothing
          } else {
            min_Count[next_L_row][next_L_col][next_R_row][next_R_col] =
                Q.front().count + 1;
            Q.push(Info(next_L_row, next_L_col, next_R_row, next_R_col,
                        Q.front().count + 1));
          }
        }
      }
      Q.pop();
    }
  }

  if (FLG) {
    printf("Yes\\n");
  } else {
    printf("No\\n");
  }
}

int main() {

  while (true) {
    scanf("%d %d", &W, &H);
    if (W == 0 && H == 0)
      break;

    func();
  }

  return 0;
}