結果

問題 No.402 最も海から遠い場所
ユーザー 0w1
提出日時 2016-11-27 22:35:05
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,214 bytes
コンパイル時間 1,789 ms
コンパイル使用メモリ 183,312 KB
実行使用メモリ 176,540 KB
最終ジャッジ日時 2024-11-27 12:22:33
合計ジャッジ時間 5,223 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 9 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };

int in_range( int h, int w, int x, int y ){
  return 0 <= x and x < h and 0 <= y and y < w;
}

signed main(){
  int H, W; cin >> H >> W;
  vector< string > G( H );
  for( int i = 0; i < H; ++i )
    cin >> G[ i ];
  vector< string > _G( H + 2 );
  for( int i = 0; i < W + 2; ++i )
    _G[ 0 ] += ".",
    _G[ H + 1 ] += ".";
  for( int i = 1; i <= H; ++i )
    _G[ i ] = "." + G[ i - 1 ] + ".";
  swap( G, _G );
  H += 2, W += 2;
  queue< tuple< int, int, int > > que;
  vector< vector< int > > vis( H, vector< int >( W ) );
  for( int i = 0; i < H; ++i )
    for( int j = 0; j < W; ++j )
      if( G[ i ][ j ] == '.' )
        que.emplace( 0, i, j ),
        vis[ i ][ j ] = 1;
  int ans = 0;
  while( not que.empty() ){
    int d, x, y; tie( d, x, y ) = que.front(); que.pop();
    ans = max( ans, d );
    for( int di = 0; di < 4; ++di ){
      int nx = x + dx[ di ];
      int ny = y + dy[ di ];
      if( not in_range( H, W, nx, ny ) ) continue;
      if( vis[ nx ][ ny ] ) continue;
      vis[ nx ][ ny ] = 1;
      que.emplace( d + 1, nx, ny );
    }
  }
  cout << ans << endl;
  return 0;
}
0