結果

問題 No.402 最も海から遠い場所
ユーザー motimoti
提出日時 2016-07-22 23:25:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,025 bytes
コンパイル時間 1,090 ms
コンパイル使用メモリ 121,404 KB
実行使用メモリ 12,248 KB
最終ジャッジ日時 2024-04-24 06:08:10
合計ジャッジ時間 6,880 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,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 main() {

  int H, W; cin >> H >> W; cin.ignore();

  rep(i, H + 2) rep(j, W + 2) {
    G[i][j] = '.';
  }

  rep(i, H) {
    rep(j, W) {
      scanf("%c", &(G[i+1][j+1]));
    }
    cin.ignore();
  }

  H += 2, W += 2;
/*
  rep(i, H) {
    rep(j, W) {
      printf("%c", G[i][j]);
    }
    puts("");
  }
//*/

  vector<pair<int, int>> v;

  rep(i, H) rep(j, W) if(G[i][j] == '.') {
    rep(k, 4) {
      int ni = i + dy[k], nj = j + dx[k];
      if(!in_range(ni, nj, H, W)) continue;
      if(G[ni][nj] == '#') {
        v.emplace_back(i, j);
      }
    }
  }

  sort(all(v));
  v.erase(unique(all(v)), v.end());

//  for(auto && e: v) {   cout << e.first << ", " << e.second << endl; }

  int ans = 0;

  rep(i, H) rep(j, W) {
    if(G[i][j] == '#') {
      int mn = inf;
      for(auto && e: v) {
        mn = min(mn, max(abs(e.first - i), abs(e.second - j)));
      }
      ans = max(mn, ans);
    }
  }

  cout << ans << endl;
    
  return 0;
}
0