結果

問題 No.402 最も海から遠い場所
ユーザー hogeover30
提出日時 2016-08-24 04:45:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 877 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 79,492 KB
実行使用メモリ 29,916 KB
最終ジャッジ日時 2024-11-08 01:48:11
合計ジャッジ時間 13,534 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 TLE * 2 -- * 4
権限があれば一括ダウンロードができます

ソースコード

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