結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 18 ms
6,940 KB
testcase_16 AC 22 ms
6,940 KB
testcase_17 AC 297 ms
33,424 KB
testcase_18 AC 510 ms
49,412 KB
testcase_19 AC 194 ms
48,972 KB
testcase_20 AC 441 ms
47,624 KB
testcase_21 AC 294 ms
66,648 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(), 1<<30);
    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) {
            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]<=v[p]+1) continue;
            q.push(np);
            v[np]=v[p]+1;
        }
    }
    int res=0;
    for(int i=0; i<a.size(); ++i) if (a[i]=='#' and res<v[i]) res=v[i];
    cout<<res<<endl;
}
0