結果

問題 No.402 最も海から遠い場所
ユーザー firiexpfiriexp
提出日時 2019-11-29 17:21:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 763 ms / 3,000 ms
コード長 1,569 bytes
コンパイル時間 1,845 ms
コンパイル使用メモリ 105,372 KB
実行使用メモリ 113,044 KB
最終ジャッジ日時 2023-08-15 23:54:03
合計ジャッジ時間 5,275 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 5 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 16 ms
5,276 KB
testcase_16 AC 22 ms
6,212 KB
testcase_17 AC 282 ms
38,524 KB
testcase_18 AC 763 ms
42,696 KB
testcase_19 AC 489 ms
113,044 KB
testcase_20 AC 536 ms
38,904 KB
testcase_21 AC 469 ms
76,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <limits>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> d(h+4, vector<int> (w+4, -1));
    queue<pair<int, int>> p;
    for (int i = 0; i <= h+1; ++i) {
        for (int j = 0; j <= w+1; ++j) {
            if(i == 0 || j == 0 || i == h+1 || j == w+1) {
                d[i+1][j+1] = 0;
                p.emplace(i, j);
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) {
            d[i+2][j+2] = (s[j] == '.' ? 0 : INF<int>);
            if(s[j] == '.'){
                p.emplace(i+1, j+1);
            }
        }
    }
    int ans = 0;
    while(!p.empty()){
        int i, j; tie(i, j) = p.front(); p.pop();
        for (int dy = -1; dy <= 1; ++dy) {
            for (int dx = -1; dx <= 1; ++dx) {
                if(!dy && !dx) continue;
                if(d[i+1+dx][j+1+dy] == -1) continue;
                if(d[i+1+dx][j+1+dy] > d[i+1][j+1]+1){
                    p.emplace(i+dx, j+dy);
                    d[i+1+dx][j+1+dy] = d[i+1][j+1]+1;
                    ans = max(ans, d[i+1][j+1]+1);
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
0