結果

問題 No.402 最も海から遠い場所
ユーザー 0w10w1
提出日時 2016-11-27 22:35:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,214 bytes
コンパイル時間 1,653 ms
コンパイル使用メモリ 183,752 KB
実行使用メモリ 176,668 KB
最終ジャッジ日時 2024-05-05 14:23:14
合計ジャッジ時間 5,384 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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