結果

問題 No.402 最も海から遠い場所
ユーザー kk
提出日時 2021-04-16 01:56:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 536 ms / 3,000 ms
コード長 1,201 bytes
コンパイル時間 2,403 ms
コンパイル使用メモリ 213,012 KB
実行使用メモリ 121,036 KB
最終ジャッジ日時 2023-09-15 04:24:51
合計ジャッジ時間 6,751 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 15 ms
5,512 KB
testcase_16 AC 19 ms
6,416 KB
testcase_17 AC 230 ms
42,592 KB
testcase_18 AC 536 ms
51,424 KB
testcase_19 AC 401 ms
121,036 KB
testcase_20 AC 390 ms
47,844 KB
testcase_21 AC 367 ms
84,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int INF = 1e6;

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

  int H, W;
  cin >> H >> W;

  W += 2;
  vector<string> bd;
  bd.push_back(string(W, '.'));
  for (int i = 0; i < H; i++) {
    string tmp;
    cin >> tmp;
    tmp = "." + tmp + ".";
    bd.push_back(tmp);
  }
  bd.push_back(string(W, '.'));
  H += 2;


  vector<vector<int> > dist(H, vector<int>(W, INF));
  queue<pair<int, int> > q;

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (bd[i][j] == '.') {
        q.emplace(i, j);
        dist[i][j] = 0;
      }
    }
  }

  while (!q.empty()) {
    int y, x;
    tie(y, x) = q.front();
    q.pop();

    for (int i = -1; i <= 1; i++) {
      for (int j = -1; j <= 1; j++) {
        int yt = y + i;
        int xt = x + j;

        if (xt < 0 || xt >= W) continue;
        if (yt < 0 || yt >= H) continue;
        if (dist[yt][xt] == INF) {
          q.emplace(yt, xt);
          dist[yt][xt] = dist[y][x] + 1;
        }
      }
    }
  }
  
  int ret = 0;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      ret = max(ret, dist[i][j]);

  cout << ret << endl;
  
  return 0;
}
0