結果

問題 No.402 最も海から遠い場所
ユーザー motimoti
提出日時 2016-07-23 00:50:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,848 bytes
コンパイル時間 1,317 ms
コンパイル使用メモリ 120,920 KB
実行使用メモリ 156,284 KB
最終ジャッジ日時 2024-04-24 06:28:55
合計ジャッジ時間 8,806 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int dx[8] = {-1,0,1,0,-1,1,1,-1};
int dy[8] = {0,-1,0,1,-1,-1,1,1};
template<class T> constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }

char G[3003][3003];
int dist[3003][3003];

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  int H, W; cin >> H >> W;
  rep(i, H + 2) {
    if(i == 0 || i == H + 1) rep(j, W + 2) G[i][j] = '.';
    else {
      cin >> (G[i] + 1);
      G[i][0] = G[i][W+1] = '.';
    }
  }

  H += 2, W += 2;

  queue<tuple<int, int, int>> q;

  rep(i, H) rep(j, W) {
    dist[i][j] = inf;
    if(G[i][j] == '.') dist[i][j] = 0, q.emplace(0, i, j);
  }

  int max = 0;

  while(!q.empty()) {
    int c, y, x; tie(c, y, x) = q.front(); q.pop();
    rep(k, 8) {
      int ny = y + dy[k], nx = x + dx[k];
      if(dist[ny][nx] > c + 1) {
        dist[ny][nx] = c + 1;
        maximize(max, c + 1);
        q.emplace(c + 1, ny, nx);
      }
    }
  }

  cout << max << endl;

  return 0;
}
0