結果

問題 No.402 最も海から遠い場所
ユーザー xuzijian629xuzijian629
提出日時 2018-11-05 22:22:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,286 bytes
コンパイル時間 2,403 ms
コンパイル使用メモリ 211,412 KB
実行使用メモリ 147,300 KB
最終ジャッジ日時 2024-04-30 22:06:51
合計ジャッジ時間 7,126 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 WA -
testcase_02 AC 2 ms
6,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
6,940 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
6,944 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
6,944 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 19 ms
6,944 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 912 ms
77,952 KB
testcase_19 AC 573 ms
147,300 KB
testcase_20 WA -
testcase_21 AC 542 ms
111,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int h, w;
    cin >> h >> w;
    vvi b(h, vi(w, 1e9));
    using ii = pair<int, int>;
    queue<ii> que;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            char c;
            cin >> c;
            if (c == '.') {
                b[i][j] = 0;
                que.push(ii(i, j));
            }
        }
    }

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

    auto ok = [&](int x, int y) {
        return 0 <= x && x < h && 0 <= y && y < w;
    };

    while (que.size()) {
        ii t = que.front();
        que.pop();
        for (int i = 0; i < 8; i++) {
            int x = t.first + dx[i];
            int y = t.second + dy[i];

            if (ok(x, y) && b[t.first][t.second] + 1 < b[x][y]) {
                b[x][y] = b[t.first][t.second] + 1;
                que.push(ii(x, y));
            }
        }
    }

    i64 nax = -1;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            nax = max(nax, b[i][j]);
        }
    }
    
    cout << nax << endl;
}
0