結果

問題 No.402 最も海から遠い場所
ユーザー hogeover30hogeover30
提出日時 2016-08-24 09:31:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 537 ms / 3,000 ms
コード長 892 bytes
コンパイル時間 718 ms
コンパイル使用メモリ 81,492 KB
実行使用メモリ 66,376 KB
最終ジャッジ日時 2024-04-25 14:52:37
合計ジャッジ時間 3,597 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 5 ms
6,940 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 16 ms
6,940 KB
testcase_16 AC 22 ms
6,940 KB
testcase_17 AC 289 ms
33,404 KB
testcase_18 AC 537 ms
50,748 KB
testcase_19 AC 188 ms
47,972 KB
testcase_20 AC 450 ms
48,720 KB
testcase_21 AC 294 ms
66,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main()
{
    int n, m; cin>>n>>m;
    m+=2;
    string a=string(m, '.');
    for(int i=0; i<n; ++i) {
        string t; cin>>t; a+="."+t+".";
    }
    a+=string(m, '.');

    queue<int> q;
    vector<int> v(a.size());
    vector<int> dir={-m-1, -m, -m+1, -1, 1, m-1, m, m+1};
    for(int i=0; i<a.size(); ++i) if (a[i]=='#') {
        bool f=false;
        for(int d: dir)
            if (a[i+d]=='.') f=true;
        if (f and !v[i]) {
            q.push(i);
            v[i]=1;
        }
    }
    
    while (q.size()) {
        int p=q.front(); q.pop();
        for(int d: dir) {
            int np=p+d;
            if (a[np]=='.' or v[np]) continue;
            q.push(np);
            v[np]=v[p]+1;
        }
    }
    cout<<*max_element(begin(v), end(v))<<endl;
}
0