Problem p01539 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
#define INF 1LL << 60

struct Comp {
  bool operator()(pair<int, ll> a, pair<int, ll> b) {
    return a.second > b.second;
  }
};

int sx, sy, gx, gy;
int lx, ly;
bool box[300][300];

ll dist[300][300][6];
bool done[300][300][6];

int dx[2][7] = {{0, 1, 1, 0, -1, -1, 0}, {0, 1, 1, 0, -1, -1, 0}};
int dy[2][7] = {{1, 0, -1, -1, -1, 0, 0}, {1, 1, 0, -1, 0, 1, 0}};

ll solve() {
  rep(i, 0, ly * ly + 1) rep(j, 0, lx * lx + 1) rep(t, 0, 6) dist[i][j][t] =
      INF;
  rep(i, 0, ly * ly + 1) rep(j, 0, lx * lx + 1) rep(t, 0, 6) done[i][j][t] =
      false;

  priority_queue<pair<int, ll>, vector<pair<int, ll>>, Comp> que;
  que.push(make_pair(sy * 1000000 + sx * 1000, 0));
  dist[sy][sx][0] = 0;

  while (!que.empty()) {
    auto q = que.top();
    que.pop();

    int y = q.first / 1000000;
    int x = (q.first % 1000000) / 1000;
    int t = q.first % 1000;

    if (y == gy && x == gx)
      return q.second;

    if (done[y][x][t])
      continue;
    done[y][x][t] = false;

    int type = (x - lx + 1000) % 2;

    rep(i, 0, 7) {
      int yy = y + dy[type][i];
      int xx = x + dx[type][i];

      if (yy < 0 || 2 * ly < yy)
        continue;
      if (xx < 0 || 2 * lx < xx)
        continue;
      if (box[yy][xx])
        continue;

      ll nc = q.second;
      int tmp = abs((x - lx) * (y - ly) * t) % 6;
      if (i != tmp)
        nc++;

      int tt = (t + 1) % 6;

      if (nc < dist[yy][xx][tt]) {
        dist[yy][xx][tt] = nc;
        que.push(make_pair(yy * 1000000 + xx * 1000 + tt, nc));
      }
    }
  }

  return -1;
}

int bx[1010];
int by[1010];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (cin >> sx >> sy >> gx >> gy) {
    int n;
    cin >> n;
    rep(i, 0, n) cin >> bx[i] >> by[i];

    cin >> lx >> ly;

    sx += lx;
    sy += ly;
    gx += lx;
    gy += ly;

    rep(i, 0, 300) rep(j, 0, 300) box[i][j] = false;
    rep(i, 0, n) box[by[i] + ly][bx[i] + lx] = true;

    cout << solve() << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
#define INF 1LL << 60

struct Comp {
  bool operator()(pair<int, ll> a, pair<int, ll> b) {
    return a.second > b.second;
  }
};

int sx, sy, gx, gy;
int lx, ly;
bool box[300][300];

ll dist[300][300][6];
bool done[300][300][6];

int dx[2][7] = {{0, 1, 1, 0, -1, -1, 0}, {0, 1, 1, 0, -1, -1, 0}};
int dy[2][7] = {{1, 0, -1, -1, -1, 0, 0}, {1, 1, 0, -1, 0, 1, 0}};

ll solve() {
  rep(i, 0, ly * 2 + 1) rep(j, 0, lx * 2 + 1) rep(t, 0, 6) dist[i][j][t] = INF;
  rep(i, 0, ly * 2 + 1) rep(j, 0, lx * 2 + 1) rep(t, 0, 6) done[i][j][t] =
      false;

  priority_queue<pair<int, ll>, vector<pair<int, ll>>, Comp> que;
  que.push(make_pair(sy * 1000000 + sx * 1000, 0));
  dist[sy][sx][0] = 0;

  while (!que.empty()) {
    auto q = que.top();
    que.pop();

    int y = q.first / 1000000;
    int x = (q.first % 1000000) / 1000;
    int t = q.first % 1000;

    if (y == gy && x == gx)
      return q.second;

    if (done[y][x][t])
      continue;
    done[y][x][t] = false;

    int type = (x - lx + 1000) % 2;

    rep(i, 0, 7) {
      int yy = y + dy[type][i];
      int xx = x + dx[type][i];

      if (yy < 0 || 2 * ly < yy)
        continue;
      if (xx < 0 || 2 * lx < xx)
        continue;
      if (box[yy][xx])
        continue;

      ll nc = q.second;
      int tmp = abs((x - lx) * (y - ly) * t) % 6;
      if (i != tmp)
        nc++;

      int tt = (t + 1) % 6;

      if (nc < dist[yy][xx][tt]) {
        dist[yy][xx][tt] = nc;
        que.push(make_pair(yy * 1000000 + xx * 1000 + tt, nc));
      }
    }
  }

  return -1;
}

int bx[1010];
int by[1010];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (cin >> sx >> sy >> gx >> gy) {
    int n;
    cin >> n;
    rep(i, 0, n) cin >> bx[i] >> by[i];

    cin >> lx >> ly;

    sx += lx;
    sy += ly;
    gx += lx;
    gy += ly;

    rep(i, 0, 300) rep(j, 0, 300) box[i][j] = false;
    rep(i, 0, n) box[by[i] + ly][bx[i] + lx] = true;

    cout << solve() << endl;
  }
}