結果

問題 No.402 最も海から遠い場所
ユーザー MisterMister
提出日時 2020-11-21 00:31:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 453 ms / 3,000 ms
コード長 1,640 bytes
コンパイル時間 897 ms
コンパイル使用メモリ 90,268 KB
実行使用メモリ 157,172 KB
最終ジャッジ日時 2023-09-30 20:21:49
合計ジャッジ時間 4,428 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 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,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 4 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 13 ms
5,944 KB
testcase_16 AC 18 ms
7,244 KB
testcase_17 AC 221 ms
51,472 KB
testcase_18 AC 453 ms
54,336 KB
testcase_19 AC 422 ms
157,172 KB
testcase_20 AC 374 ms
48,580 KB
testcase_21 AC 353 ms
103,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/vector_alias.hpp"

#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
#line 2 "main.cpp"

#include <iostream>
#line 5 "main.cpp"
#include <string>
#include <queue>
#include <tuple>

void solve() {
    int h, w;
    std::cin >> h >> w;

    std::vector<std::string> ss(h);
    for (auto &s : ss) std::cin >> s;

    auto dist = vec(h, vec(w, -1));
    std::queue<std::tuple<int, int, int>> que;

    for (int x = -1; x <= h; ++x) {
        for (int y = -1; y <= w; ++y) {
            if (x < 0 || h <= x ||
                y < 0 || w <= y) {
                que.emplace(0, x, y);
            } else if (ss[x][y] == '.') {
                dist[x][y] = 0;
                que.emplace(0, x, y);
            }
        }
    }

    while (!que.empty()) {
        auto [d, x, y] = que.front();
        que.pop();

        for (int dx = -1; dx <= 1; ++dx) {
            for (int dy = -1; dy <= 1; ++dy) {
                int nx = x + dx,
                    ny = y + dy;

                if (nx < 0 || h <= nx ||
                    ny < 0 || w <= ny ||
                    dist[nx][ny] != -1) continue;
                dist[nx][ny] = d + 1;
                que.emplace(dist[nx][ny], nx, ny);
            }
        }
    }

    int ans = 0;
    for (int x = 0; x < h; ++x) {
        for (int y = 0; y < w; ++y) {
            ans = std::max(ans, dist[x][y]);
        }
    }
    std::cout << ans << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0