結果

問題 No.402 最も海から遠い場所
ユーザー uenokuuenoku
提出日時 2016-08-31 04:43:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 874 ms / 3,000 ms
コード長 1,503 bytes
コンパイル時間 808 ms
コンパイル使用メモリ 89,840 KB
実行使用メモリ 129,744 KB
最終ジャッジ日時 2024-04-26 21:24:26
合計ジャッジ時間 6,293 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
20,992 KB
testcase_01 AC 14 ms
20,992 KB
testcase_02 AC 14 ms
21,120 KB
testcase_03 AC 14 ms
20,992 KB
testcase_04 AC 14 ms
20,992 KB
testcase_05 AC 14 ms
20,992 KB
testcase_06 AC 14 ms
20,992 KB
testcase_07 AC 14 ms
21,120 KB
testcase_08 AC 15 ms
21,120 KB
testcase_09 AC 14 ms
20,992 KB
testcase_10 AC 14 ms
21,120 KB
testcase_11 AC 15 ms
20,864 KB
testcase_12 AC 14 ms
20,992 KB
testcase_13 AC 20 ms
21,376 KB
testcase_14 AC 16 ms
21,120 KB
testcase_15 AC 48 ms
22,400 KB
testcase_16 AC 48 ms
23,168 KB
testcase_17 AC 652 ms
47,444 KB
testcase_18 AC 874 ms
27,008 KB
testcase_19 AC 873 ms
129,744 KB
testcase_20 AC 790 ms
21,248 KB
testcase_21 AC 810 ms
76,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include "math.h"
#include <complex>
#include <iomanip>
#include <map>
#define ifor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;
typedef long double ld;
typedef long long int  lli;
typedef pair<int,int> P;
const double eps = 1e-11;
int vex[4]={1,0,-1,0};
int vey[4]={0,1,0,-1};
typedef vector<double> Vec;
typedef vector<int> vec;
typedef vector<Vec> MAT;
typedef vector<vec> mat;
lli MOD=1000000007;
int main(){
  int H,W;
  cin >> H >> W;
  bool fi[3004][3004];
  bool dis [3004][3004];
  queue<pair<P,int> > que;
  rep(i,H+2){
    rep(j,W+2){
      if(j==W+1||j==0||i==0||i==H+1)que.push(make_pair(P(i,j),0));
    }
  }
  char c;
  rep(i,H)rep(j,W){
    cin>>c;
  if(c=='#')fi[i+1][j+1]=true;
    if(c=='.')que.push(make_pair(P(i+1,j+1),0));
  }
  int ans = 0;
  while(!que.empty()){
    P p= que.front().first;
    int d = que.front().second;
    ans = max(ans,que.front().second);
    que.pop();
    for(int i = -1;i<=1;i++){
      for(int j = -1;j<=1;j++){
        if(p.first+i<0||p.second +j<0)continue;
        if(!(i==0&&j==0)&&!dis[p.first+i][p.second+j]&&fi[p.first+i][p.second+j]){
          dis[p.first+i][p.second+j]=true;
          que.push(make_pair(P(i+p.first,j+p.second),d+1));
        }
      }
    }
  }
  cout<<ans<<endl;
}

0