Problem p01539 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
// #define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define INF 100000000

struct P {
  int x, y, t, ignore;
  bool operator>(const P &p) const { return ignore > p.ignore; }
};

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

int G[201][201][6];
bool obstacle[201][201];

int main() {
  int ix, iy, ox, oy;
  cin >> ix >> iy >> ox >> oy;
  ix += 100;
  iy += 100;
  ox += 100;
  oy += 100;
  int n;
  cin >> n;
  REP(i, n) {
    int x, y;
    cin >> x >> y;
    x += 100;
    y += 100;
    obstacle[y][x] = true;
  }
  int W, H;
  cin >> W >> H;
  W += 100;
  H += 100;

  fill_n((int *)G, 201 * 201 * 6, INF);

  priority_queue<P, vector<P>, greater<P>> que;
  que.push({ix, iy, 0, 0});
  G[iy][ix][0] = 0;
  while (!que.empty()) {
    P p = que.top();
    que.pop();

    if (p.x == ox && p.y == oy) {
      cout << p.ignore << endl;
      return 0;
    }

    int order = abs((p.x - 100) * (p.y - 100) * p.t) % 6;
    REP(i, 7) {
      int sx = p.x + dx[i];
      int sy = p.y + dy[abs(p.x - 100) % 2][i];
      if (-W <= sx - 100 && sx - 100 <= W && -H <= sy - 100 && sy - 100 <= H) {
        if (!obstacle[sy][sx]) {
          int t = (p.t + 1) % 6;
          int ignore = p.ignore + (i == order ? 0 : 1);
          if (G[sy][sx][t] > ignore) {
            G[sy][sx][t] = ignore;
            que.push({sx, sy, p.t + 1, ignore});
          }
        }
      }
    }
  }
  cout << -1 << endl;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
// #define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define INF 100000000

struct P {
  int x, y, t, ignore;
  bool operator>(const P &p) const { return ignore > p.ignore; }
};

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

int G[201][201][6];
bool obstacle[201][201];

int main() {
  int ix, iy, ox, oy;
  cin >> ix >> iy >> ox >> oy;
  ix += 100;
  iy += 100;
  ox += 100;
  oy += 100;
  int n;
  cin >> n;
  REP(i, n) {
    int x, y;
    cin >> x >> y;
    x += 100;
    y += 100;
    obstacle[y][x] = true;
  }
  int W, H;
  cin >> W >> H;

  fill_n((int *)G, 201 * 201 * 6, INF);

  priority_queue<P, vector<P>, greater<P>> que;
  que.push({ix, iy, 0, 0});
  G[iy][ix][0] = 0;
  while (!que.empty()) {
    P p = que.top();
    que.pop();

    if (p.x == ox && p.y == oy) {
      cout << p.ignore << endl;
      return 0;
    }

    int order = abs((p.x - 100) * (p.y - 100) * p.t) % 6;
    REP(i, 7) {
      int sx = p.x + dx[i];
      int sy = p.y + dy[abs(p.x - 100) % 2][i];
      if (-W <= sx - 100 && sx - 100 <= W && -H <= sy - 100 && sy - 100 <= H) {
        if (!obstacle[sy][sx]) {
          int t = (p.t + 1) % 6;
          int ignore = p.ignore + (i == order ? 0 : 1);
          if (G[sy][sx][t] > ignore) {
            G[sy][sx][t] = ignore;
            que.push({sx, sy, p.t + 1, ignore});
          }
        }
      }
    }
  }
  cout << -1 << endl;
}