結果

問題 No.402 最も海から遠い場所
ユーザー 0w10w1
提出日時 2016-11-27 22:39:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 857 ms / 3,000 ms
コード長 1,242 bytes
コンパイル時間 2,226 ms
コンパイル使用メモリ 180,552 KB
実行使用メモリ 176,664 KB
最終ジャッジ日時 2023-08-18 08:35:10
合計ジャッジ時間 6,742 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 20 ms
6,596 KB
testcase_16 AC 28 ms
8,092 KB
testcase_17 AC 347 ms
62,444 KB
testcase_18 AC 857 ms
73,772 KB
testcase_19 AC 628 ms
176,664 KB
testcase_20 AC 582 ms
68,160 KB
testcase_21 AC 586 ms
122,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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 < 8; ++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