結果

問題 No.402 最も海から遠い場所
ユーザー merom686merom686
提出日時 2018-03-06 21:23:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 310 ms / 3,000 ms
コード長 1,283 bytes
コンパイル時間 807 ms
コンパイル使用メモリ 87,656 KB
実行使用メモリ 57,844 KB
最終ジャッジ日時 2023-10-21 18:43:05
合計ジャッジ時間 4,376 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 10 ms
4,584 KB
testcase_16 AC 12 ms
5,016 KB
testcase_17 AC 152 ms
20,944 KB
testcase_18 AC 310 ms
23,356 KB
testcase_19 AC 251 ms
57,844 KB
testcase_20 AC 234 ms
20,876 KB
testcase_21 AC 223 ms
39,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int h, w;
    cin >> h >> w;

    queue<pair<int16_t, int16_t>> q;
    for (int i = 2; i < h + 2; i++) {
        q.push({ i, 1 });
        q.push({ i, w + 2 });
    }
    for (int j = 2; j < w + 2; j++) {
        q.push({ 1, j });
        q.push({ h + 2, j });
    }

    vector<vector<int16_t>> a(h + 4, vector<int16_t>(w + 4, 0));
    string s;
    for (int i = 0; i < h; i++) {
        cin >> s;
        for (int j = 0; j < w; j++) {
            if (s[j] == '#') {
                a[i + 2][j + 2] = 1 << 14;
            } else {
                q.push({ i + 2, j + 2 });
            }
        }
    }

    int r = 0;
    while (!q.empty()) {
        auto p = q.front(); q.pop();
        int d = a[p.first][p.second] + 1;
        for (int i = p.first - 1; i <= p.first + 1; i++) {
            for (int j = p.second - 1; j <= p.second + 1; j++) {
                if (a[i][j] > d) {
                    r = a[i][j] = d;
                    q.push({ i, j });
                }
            }
        }
    }

    cout << r << endl;

    return 0;
}
0