結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,756 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 179 ms
6,944 KB
testcase_14 AC 57 ms
6,940 KB
testcase_15 AC 2,648 ms
6,940 KB
testcase_16 TLE -
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

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