結果

問題 No.402 最も海から遠い場所
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-06-02 14:53:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 476 ms / 3,000 ms
コード長 1,438 bytes
コンパイル時間 1,605 ms
コンパイル使用メモリ 158,676 KB
実行使用メモリ 125,812 KB
最終ジャッジ日時 2023-08-15 15:13:45
合計ジャッジ時間 5,012 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 16 ms
5,200 KB
testcase_16 AC 21 ms
6,148 KB
testcase_17 AC 271 ms
38,240 KB
testcase_18 AC 415 ms
22,016 KB
testcase_19 AC 476 ms
125,812 KB
testcase_20 AC 388 ms
16,184 KB
testcase_21 AC 437 ms
72,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.02 14:53:26
**/

#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(make_tuple(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(make_tuple(i, -1, 0));
        que.push(make_tuple(i, w, 0));
    }
    for (int i = 0; i < w; i++) {
        que.push(make_tuple(-1, i, 0));
        que.push(make_tuple(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 < 9; i++) {
            int x = nx + dx[i], y = ny + dy[i];
            if (x >= 0 && x < h && y >= 0 && y < w && !visited[x][y]) {
                que.push(make_tuple(x, y, d + 1));
                visited[x][y] = true;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0