結果

問題 No.402 最も海から遠い場所
ユーザー rickythetarickytheta
提出日時 2016-07-23 01:11:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,009 ms / 3,000 ms
コード長 1,885 bytes
コンパイル時間 1,981 ms
コンパイル使用メモリ 163,596 KB
実行使用メモリ 130,436 KB
最終ジャッジ日時 2024-04-24 07:01:41
合計ジャッジ時間 6,526 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
52,588 KB
testcase_01 AC 30 ms
52,484 KB
testcase_02 AC 31 ms
52,616 KB
testcase_03 AC 31 ms
52,376 KB
testcase_04 AC 31 ms
52,552 KB
testcase_05 AC 31 ms
52,292 KB
testcase_06 AC 31 ms
52,236 KB
testcase_07 AC 36 ms
52,352 KB
testcase_08 AC 36 ms
52,608 KB
testcase_09 AC 36 ms
52,352 KB
testcase_10 AC 37 ms
52,608 KB
testcase_11 AC 37 ms
52,480 KB
testcase_12 AC 37 ms
52,352 KB
testcase_13 AC 40 ms
53,504 KB
testcase_14 AC 39 ms
53,632 KB
testcase_15 AC 53 ms
56,320 KB
testcase_16 AC 64 ms
57,728 KB
testcase_17 AC 328 ms
94,316 KB
testcase_18 AC 1,009 ms
97,536 KB
testcase_19 AC 115 ms
93,824 KB
testcase_20 AC 742 ms
94,080 KB
testcase_21 AC 323 ms
130,436 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:44:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   44 |   scanf("%d%d",&h,&w);
      |   ~~~~~^~~~~~~~~~~~~~
main.cpp:47:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |     scanf("%s",s);
      |     ~~~~~^~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int h,w;
int mp[3535][3535];
int mn[3535][3535];
int dx[] = {1,0,-1,0,1,1,-1,-1};
int dy[] = {0,1,0,-1,1,-1,-1,1};

const int NICO = 830252521;

int main(){
  REP(i,3535)REP(j,3535)mn[i][j] = NICO;
  scanf("%d%d",&h,&w);
  REP(i,h){
    char s[3531];
    scanf("%s",s);
    REP(j,w){
      mp[i][j] = s[j]=='.';
    }
  }
  queue<pii> Q;
  REP(i,h)REP(j,w){
    if(mp[i][j])continue;
    if(i==0 || j==0 || i==h-1 || j==w-1){
      mn[i][j] = 1;
      Q.push(pii(i,j));
    }else{
      REP(d,8){
        if(mp[i+dy[d]][j+dx[d]]){
          mn[i][j] = 1;
          Q.push(pii(i,j));
          break;
        }
      }
    }
  }
  int ans = 0;
  while(!Q.empty()){
    pii P = Q.front(); Q.pop();
    int y = P.first;
    int x = P.second;
    CHMAX(ans,mn[y][x]);
    REP(d,8){
      int ny = y+dy[d];
      int nx = x+dx[d];
      if(ny<0 || nx<0 || ny>=h || nx>=w)continue;
      if(mp[ny][nx])continue;
      if(mn[ny][nx] != NICO)continue;
      mn[ny][nx] = mn[y][x] + 1;
      Q.push(pii(ny,nx));
    }
  }
  printf("%d\n",ans);
  return 0;
}
0