結果

問題 No.402 最も海から遠い場所
ユーザー hogeover30hogeover30
提出日時 2016-08-24 04:58:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,063 bytes
コンパイル時間 820 ms
コンパイル使用メモリ 87,876 KB
実行使用メモリ 201,332 KB
最終ジャッジ日時 2024-04-25 14:51:21
合計ジャッジ時間 8,806 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,760 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 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 1 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 1 ms
6,940 KB
testcase_13 AC 13 ms
6,944 KB
testcase_14 AC 4 ms
6,940 KB
testcase_15 AC 68 ms
10,240 KB
testcase_16 AC 63 ms
13,920 KB
testcase_17 AC 1,538 ms
134,496 KB
testcase_18 AC 511 ms
54,008 KB
testcase_19 AC 273 ms
47,480 KB
testcase_20 AC 442 ms
49,320 KB
testcase_21 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <vector>
#include <set>
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, '.');

    set<int> s;
    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]=='.') {
        for(int d: dir) {
            int k=i+d;
            if (k<0 or k>=a.size() or a[k]=='.') continue;
            s.insert(k);
        }
    }
    
    vector<int> v(a.size(), 1<<30);
    queue<int> q;
    for(int e: s) {
        q.push(e);
        v[e]=1;
    }
    while (q.size()) {
        int p=q.front(); q.pop();
        for(int d: dir) {
            int np=p+d;
            if (np<0 or np>=a.size() or 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