Problem p03053 (C++)

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

typedef vector<vector<char>> field_t;
typedef pair<int, int> point_t;

// point_tの足し算
point_t operator+(const point_t &lhs, const point_t &rhs) {
  point_t res;
  res.first = lhs.first + rhs.first;
  res.second = lhs.second + rhs.second;
  return res;
}

// 範囲内外判定
bool is_in_field(int col, int row, const point_t &point) {
  int c = point.first;
  int r = point.second;
  return ((c >= 0 && c < col) && (r >= 0 && r < row));
}

// 配列要素の最大値
int max_v(vector<vector<int>> &v) {
  int res = v.at(0).at(0);
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < v.at(0).size(); j++) {
      res = max(res, v.at(i).at(j));
    }
  }
  return res;
}

// 多点WFS
int solve(int H, int W, queue<point_t> &que, vector<vector<int>> &v) {
  vector<point_t> points = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  while (!que.empty()) {
    point_t cur = que.front();
    que.pop();
    int col_cur = cur.first;
    int row_cur = cur.second;
    for (const auto &p : points) {
      point_t next = cur + p;
      int col_next = next.first;
      int row_next = next.second;
      if (is_in_field(H, W, next)) {
        if (v.at(col_next).at(row_next) == -1) {
          v.at(col_next).at(row_next) = v.at(col_cur).at(row_cur) + 1;
          que.push(next);
        }
      }
    }
  }
  return max_v(v);
}

int main() {
  // 入力
  int H, W;
  cin >> H >> W;

  field_t A(H, vector<char>(W));
  queue<point_t> que;

  vector<vector<int>> v(W, vector<int>(H, -1)); // 訪問までに必要な回数
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A.at(i).at(j);
      if (A.at(i).at(j) == '#') {
        que.push({i, j});  // 開始位置の代入
        v.at(i).at(j) = 0; // 開始位置の訪問回数を0に
      }
    }
  }

  // 出力
  cout << solve(H, W, que, v) << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef vector<vector<char>> field_t;
typedef pair<int, int> point_t;

// point_tの足し算
point_t operator+(const point_t &lhs, const point_t &rhs) {
  point_t res;
  res.first = lhs.first + rhs.first;
  res.second = lhs.second + rhs.second;
  return res;
}

// 範囲内外判定
bool is_in_field(int col, int row, const point_t &point) {
  int c = point.first;
  int r = point.second;
  return ((c >= 0 && c < col) && (r >= 0 && r < row));
}

// 配列要素の最大値
int max_v(vector<vector<int>> &v) {
  int res = v.at(0).at(0);
  for (int i = 0; i < v.size(); i++) {
    for (int j = 0; j < v.at(0).size(); j++) {
      res = max(res, v.at(i).at(j));
    }
  }
  return res;
}

// 多点WFS
int solve(int H, int W, queue<point_t> &que, vector<vector<int>> &v) {
  vector<point_t> points = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
  while (!que.empty()) {
    point_t cur = que.front();
    que.pop();
    int col_cur = cur.first;
    int row_cur = cur.second;
    for (const auto &p : points) {
      point_t next = cur + p;
      int col_next = next.first;
      int row_next = next.second;
      if (is_in_field(H, W, next)) {
        if (v.at(col_next).at(row_next) == -1) {
          v.at(col_next).at(row_next) = v.at(col_cur).at(row_cur) + 1;
          que.push(next);
        }
      }
    }
  }
  return max_v(v);
}

int main() {
  // 入力
  int H, W;
  cin >> H >> W;

  field_t A(H, vector<char>(W));
  queue<point_t> que;

  vector<vector<int>> v(H, vector<int>(W, -1)); // 訪問までに必要な回数
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A.at(i).at(j);
      if (A.at(i).at(j) == '#') {
        que.push({i, j});  // 開始位置の代入
        v.at(i).at(j) = 0; // 開始位置の訪問回数を0に
      }
    }
  }

  // 出力
  cout << solve(H, W, que, v) << endl;
  return 0;
}