結果

問題 No.402 最も海から遠い場所
ユーザー AquariusAquarius
提出日時 2019-10-15 16:12:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,350 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 172,540 KB
実行使用メモリ 813,936 KB
最終ジャッジ日時 2023-08-28 14:55:12
合計ジャッジ時間 7,592 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 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,376 KB
testcase_13 AC 8 ms
6,608 KB
testcase_14 AC 5 ms
7,064 KB
testcase_15 AC 32 ms
20,180 KB
testcase_16 AC 46 ms
28,076 KB
testcase_17 AC 607 ms
248,116 KB
testcase_18 AC 1,099 ms
104,532 KB
testcase_19 MLE -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int inf = 1e9;

using PP = pair<int, int>;
int h, w;
int a[3002][3002];
string s[3002];
int main() {
  cin >> h >> w;
  s[0] = string(w + 2, '.');
  s[h + 1] = string(w + 2, '.');
  for (int i = 0; i < h; ++i) {
    string t;
    cin >> t;
    s[i + 1] = '.' + t + '.';
  }
  
  for (int i = 0; i < h + 2; ++i) {
    for (int j = 0; j < w + 2; ++j) {
      a[i][j] = inf;
    }
  }
  
  queue<pair<int, PP>> q;
  for (int i = 0; i < h + 2; ++i) {
    for (int j = 0; j < w + 2; ++j) {
      if (i == 0 || i == h + 1
       || j == 0 || j == w + 1
       || s[i][j] == '.') {
        q.push(make_pair(0, PP(i, j)));
      }
    }
  }
  
  const int di[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
  const int dj[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
  while (!q.empty()) {
    auto p = q.front(); q.pop();
    int d = p.first;
    int i = p.second.first;
    int j = p.second.second;
    if (i < 0 || i >= h + 2) continue;
    if (j < 0 || j >= w + 2) continue;
    if (a[i][j] != inf) continue;
    a[i][j] = d;
    
    for (int k = 0; k < 8; ++k) {
      int ni = i + di[k];
      int nj = j + dj[k];
      q.push(make_pair(d + 1, PP(ni, nj)));
    }
  }
  
  int mx = 0;
  for (int i = 0; i < h + 2; ++i) {
    for (int j = 0; j < w + 2; ++j) {
      mx = max(mx, a[i][j]);
    }
  }
  cout << mx << endl;
}
0