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

#include <cstdio>
#include <iomanip>
#include <iostream>

#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#include <algorithm>
#include <functional>
#include <numeric>

#include <cctype>

#include <complex>
#include <sstream>
#include <string>

using namespace std;

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define tr(it, container)                                                      \\
  for (typeof(container.begin()) it = container.begin();                       \\
       it != container.end(); ++it)
#define mp(a, b) make_pair((a), (b))

typedef long long ll;
typedef complex<double> P;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
const double EPS = 1e-9;
const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int daysleap[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int ddx1[] = {0, -1, 0, 1, 1, 1};
const int ddy1[] = {-1, 0, 1, 1, 0, -1};
const int ddx0[] = {-1, -1, -1, 0, 1, 0};
const int ddy0[] = {-1, 0, 1, 1, 0, -1};

int main() {
  while (true) {
    int m, n, s;
    cin >> m;
    if (m == 0)
      break;
    cin >> n >> s;
    vector<pair<int, int>> V(s);

    rep(i, s) {
      int x, y;
      cin >> x >> y;
      x--;
      y--;
      V[i] = mp(x, y);
    }
    vector<vector<int>> depth(n, vector<int>(m, 10000));
    // x,y,depth
    queue<pair<pair<int, int>, int>> Q;
    rep(i, s) { Q.push(mp(V[i], 0)); }
    while (!Q.empty()) {
      pair<pair<int, int>, int> p = Q.front();
      int x = p.first.first;
      int y = p.first.second;
      int d = p.second;
      Q.pop();
      if (depth[y][x] <= d)
        continue;
      depth[y][x] = d;
      for (int i = 0; i < 6; i++) {
        int newx, newy;
        if (y % 2 == 0) {
          newx = x + ddx0[i];
          newy = y + ddy0[i];
        } else {
          newx = x + ddx1[i];
          newy = y + ddy1[i];
        }
        if (newx == -1 || newy == -1 || newx == m || newy == n) {
          continue;
        }
        Q.push(mp(mp(newx, newy), d + 1));
      }
    }

    int t;
    cin >> t;
    vector<pair<int, int>> Con(t);
    rep(i, t) {
      int p, q;
      cin >> p >> q;
      p--;
      q--;
      Con[i] = mp(p, q);
    }
    int maxcnt = -1;

    /*
            rep(i,n){
                rep(j,m){
                    cerr << depth[i][j] << " ";
                }
                cerr << endl;
            }
    */

    rep(cont, t) {
      pair<int, int> cc = Con[cont];
      int cnt = 0;
      // x,y,depth
      queue<pair<pair<int, int>, int>> Qc;
      Qc.push(mp(cc, 0));
      vector<vector<int>> depthc = depth;
      while (!Qc.empty()) {
        pair<pair<int, int>, int> p = Qc.front();
        int x = p.first.first;
        int y = p.first.second;
        int d = p.second;
        Qc.pop();
        if (depthc[y][x] <= d)
          continue;

        depthc[y][x] = d;
        cnt++;
        for (int i = 0; i < 6; i++) {
          int newx, newy;
          if (y % 2 == 0) {
            newx = x + ddx0[i];
            newy = y + ddy0[i];
          } else {
            newx = x + ddx1[i];
            newy = y + ddy1[i];
          }

          if (newx == -1 || newy == -1 || newx == m || newy == n) {
            continue;
          }
          Qc.push(mp(mp(newx, newy), d + 1));
        }
      }
      maxcnt = max(maxcnt, cnt);
    }
    cout << maxcnt << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iomanip>
#include <iostream>

#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>

#include <algorithm>
#include <functional>
#include <numeric>

#include <cctype>

#include <complex>
#include <sstream>
#include <string>

using namespace std;

#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define tr(it, container)                                                      \\
  for (typeof(container.begin()) it = container.begin();                       \\
       it != container.end(); ++it)
#define mp(a, b) make_pair((a), (b))

typedef long long ll;
typedef complex<double> P;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
const double EPS = 1e-9;
const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int daysleap[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int ddx1[] = {0, -1, 0, 1, 1, 1};
const int ddy1[] = {-1, 0, 1, 1, 0, -1};
const int ddx0[] = {-1, -1, -1, 0, 1, 0};
const int ddy0[] = {-1, 0, 1, 1, 0, -1};

int main() {
  while (true) {
    int m, n, s;
    cin >> m;
    if (m == 0)
      break;
    cin >> n >> s;
    vector<pair<int, int>> V(s);

    rep(i, s) {
      int x, y;
      cin >> x >> y;
      x--;
      y--;
      V[i] = mp(x, y);
    }
    vector<vector<int>> depth(n, vector<int>(m, 10000));
    // x,y,depth
    queue<pair<pair<int, int>, int>> Q;
    rep(i, s) { Q.push(mp(V[i], 0)); }
    while (!Q.empty()) {
      pair<pair<int, int>, int> p = Q.front();
      int x = p.first.first;
      int y = p.first.second;
      int d = p.second;
      Q.pop();
      if (depth[y][x] <= d)
        continue;
      depth[y][x] = d;
      for (int i = 0; i < 6; i++) {
        int newx, newy;
        if (y % 2 == 0) {
          newx = x + ddx0[i];
          newy = y + ddy0[i];
        } else {
          newx = x + ddx1[i];
          newy = y + ddy1[i];
        }
        if (newx == -1 || newy == -1 || newx == m || newy == n) {
          continue;
        }
        Q.push(mp(mp(newx, newy), d + 1));
      }
    }

    int t;
    cin >> t;
    vector<pair<int, int>> Con(t);
    rep(i, t) {
      int p, q;
      cin >> p >> q;
      p--;
      q--;
      Con[i] = mp(p, q);
    }
    int maxcnt = -1;

    /*
            rep(i,n){
                rep(j,m){
                    cerr << depth[i][j] << " ";
                }
                cerr << endl;
            }
    */
    rep(cont, t) {
      pair<int, int> cc = Con[cont];
      int cnt = 0;
      queue<pair<pair<int, int>, int>> Qc;
      Qc.push(mp(cc, 0));
      vector<vector<int>> depthc = depth;
      while (!Qc.empty()) {
        pair<pair<int, int>, int> p = Qc.front();
        int x = p.first.first;
        int y = p.first.second;
        int d = p.second;
        Qc.pop();
        if (depthc[y][x] <= d)
          continue;

        depthc[y][x] = d;
        cnt++;
        for (int i = 0; i < 6; i++) {
          int newx, newy;
          if (y % 2 == 0) {
            newx = x + ddx0[i];
            newy = y + ddy0[i];
          } else {
            newx = x + ddx1[i];
            newy = y + ddy1[i];
          }

          if (newx == 0 || newy == 0 || newx == m || newy == n) {
            continue;
          }
          Qc.push(mp(mp(newx, newy), d + 1));
        }
      }
      maxcnt = max(maxcnt, cnt);
    }
    cout << maxcnt << endl;
  }
  return 0;
}