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

#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL << 60;
const long long int Mod = 1000000007;
using ll = long long int;
using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define rp(i, N) for (ll i = 0; i < (ll)N; i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
template <class T> bool chmax(T &former, const T &b) {
  if (former < b) {
    former = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &former, const T &b) {
  if (b < former) {
    former = b;
    return true;
  }
  return false;
}
template <class T> T sqar(T x) { return x * x; } // sqrt(x)は平方根;
#define Sort(v)                                                                \\
  std::sort(v.begin(), v.end(),                                                \\
            std::greater<decltype(v[0])>()) // 降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v>>
template <class T> inline void princ(T x) { cout << x << " "; };
template <class T> inline void print(T x) { cout << x << "\\n"; };
template <class T> inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T> inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
///////////////////////////////////////////////////////////////////////////////////

void solve() {
  ll h, w;
  cin >> h >> w;
  ll ch, cw, dh, dw;
  cin >> ch >> cw >> dh >> dw;
  ch--;
  cw--;
  dh--;
  dw--;
  vector<vector<char>> s(h, vector<char>(w));
  rp(i, h) {
    rp(j, w) { cin >> s[i][j]; }
  }
  matrix mat(h, Vi(w, 1000000000));
  vector<queue<PLL>> vq(250000);
  vq[0].push(mp(ch, cw));
  mat[ch][cw] = 0;
  rp(dist, 250000) {
    while (!vq[dist].empty()) {
      PLL pl = vq[dist].front();
      vq[dist].pop();
      repi(i, -2, 3) {
        repi(j, -2, 3) {
          if (i == 0 && j == 0)
            continue;
          if (pl.first + i < 0 || pl.first + i >= h)
            continue;
          if (pl.second + j < 0 || pl.second + j >= w)
            continue;
          if (s[pl.first + i][pl.second + j] == '#')
            continue;
          if (mat[pl.first][pl.second] < dist)
            continue;

          if (abs(i) + abs(j) == 1) {
            if (chmin(mat[pl.first + i][pl.second + j],
                      mat[pl.first][pl.second]))
              vq[dist].push(mp(pl.first + i, pl.second + j));
          } else {
            if (chmin(mat[pl.first + i][pl.second + j],
                      mat[pl.first][pl.second] + 1))
              vq[dist + 1].push(mp(pl.first + i, pl.second + j));
          }
        }
      }
    }
  }
  if (mat[dh][dw] > 10000000)
    print(-1);
  else
    print(mat[dh][dw]);

  return;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(30);
  solve();
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL << 60;
const long long int Mod = 1000000007;
using ll = long long int;
using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define rp(i, N) for (ll i = 0; i < (ll)N; i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
template <class T> bool chmax(T &former, const T &b) {
  if (former < b) {
    former = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &former, const T &b) {
  if (b < former) {
    former = b;
    return true;
  }
  return false;
}
template <class T> T sqar(T x) { return x * x; } // sqrt(x)は平方根;
#define Sort(v)                                                                \\
  std::sort(v.begin(), v.end(),                                                \\
            std::greater<decltype(v[0])>()) // 降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v>>
template <class T> inline void princ(T x) { cout << x << " "; };
template <class T> inline void print(T x) { cout << x << "\\n"; };
template <class T> inline void Yes(T condition) {
  if (condition)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
template <class T> inline void YES(T condition) {
  if (condition)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
///////////////////////////////////////////////////////////////////////////////////

void solve() {
  ll h, w;
  cin >> h >> w;
  ll ch, cw, dh, dw;
  cin >> ch >> cw >> dh >> dw;
  ch--;
  cw--;
  dh--;
  dw--;
  vector<vector<char>> s(h, vector<char>(w));
  rp(i, h) {
    rp(j, w) { cin >> s[i][j]; }
  }
  matrix mat(h, Vi(w, 1000000000));
  vector<queue<PLL>> vq(1000);
  vq[0].push(mp(ch, cw));
  mat[ch][cw] = 0;
  rp(dist, 1000) {
    while (!vq[dist].empty()) {
      PLL pl = vq[dist].front();
      vq[dist].pop();
      repi(i, -2, 3) {
        repi(j, -2, 3) {
          if (i == 0 && j == 0)
            continue;
          if (pl.first + i < 0 || pl.first + i >= h)
            continue;
          if (pl.second + j < 0 || pl.second + j >= w)
            continue;
          if (s[pl.first + i][pl.second + j] == '#')
            continue;
          if (mat[pl.first][pl.second] < dist)
            continue;

          if (abs(i) + abs(j) == 1) {
            if (chmin(mat[pl.first + i][pl.second + j],
                      mat[pl.first][pl.second]))
              vq[dist].push(mp(pl.first + i, pl.second + j));
          } else {
            if (chmin(mat[pl.first + i][pl.second + j],
                      mat[pl.first][pl.second] + 1))
              vq[dist + 1].push(mp(pl.first + i, pl.second + j));
          }
        }
      }
    }
  }
  if (mat[dh][dw] > 10000000)
    print(-1);
  else
    print(mat[dh][dw]);

  return;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(30);
  solve();
  return 0;
}