結果
問題 |
No.402 最も海から遠い場所
|
ユーザー |
![]() |
提出日時 | 2020-06-02 14:47:23 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,378 bytes |
コンパイル時間 | 2,483 ms |
コンパイル使用メモリ | 172,888 KB |
実行使用メモリ | 125,972 KB |
最終ジャッジ日時 | 2024-11-23 22:33:26 |
合計ジャッジ時間 | 7,480 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 16 WA * 3 |
ソースコード
/** * @FileName a.cpp * @Author kanpurin * @Created 2020.06.02 14:47:18 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int main() { int h, w; cin >> h >> w; vector< string > g(h); vector< vector< bool > > visited(h, vector< bool >(w, false)); queue< tuple< int, int, int > > que; for (int i = 0; i < h; i++) { cin >> g[i]; for (int j = 0; j < w; j++) { if (g[i][j] == '.') { que.push({i, j, 0}); visited[i][j] = true; } } } const int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}, dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; for (int i = -1; i <= h; i++) { que.push({i, -1, 0}); que.push({i, w, 0}); } for (int i = 0; i < w; i++) { que.push({-1, i, 0}); que.push({h, i, 0}); } int ans = 0; while (!que.empty()) { auto p = que.front(); que.pop(); int nx = get< 0 >(p); int ny = get< 1 >(p); int d = get< 2 >(p); ans = max(ans, d); for (int i = 0; i < 8; i++) { int x = nx + dx[i], y = ny + dy[i]; if (x >= 0 && x < h && y >= 0 && y < w && !visited[x][y]) { que.push({x, y, d + 1}); visited[x][y] = true; } } } cout << ans << endl; return 0; }