結果
問題 |
No.402 最も海から遠い場所
|
ユーザー |
|
提出日時 | 2016-11-27 22:39:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 904 ms / 3,000 ms |
コード長 | 1,242 bytes |
コンパイル時間 | 2,045 ms |
コンパイル使用メモリ | 182,408 KB |
実行使用メモリ | 176,544 KB |
最終ジャッジ日時 | 2024-11-27 12:22:54 |
合計ジャッジ時間 | 6,491 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#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; }