結果

問題 No.402 最も海から遠い場所
ユーザー btkbtk
提出日時 2016-07-27 15:46:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 520 ms / 3,000 ms
コード長 1,216 bytes
コンパイル時間 1,739 ms
コンパイル使用メモリ 179,184 KB
実行使用メモリ 121,180 KB
最終ジャッジ日時 2023-08-06 14:52:36
合計ジャッジ時間 4,910 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 12 ms
5,568 KB
testcase_16 AC 16 ms
6,292 KB
testcase_17 AC 198 ms
42,632 KB
testcase_18 AC 520 ms
51,640 KB
testcase_19 AC 315 ms
121,180 KB
testcase_20 AC 346 ms
47,848 KB
testcase_21 AC 295 ms
84,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

struct I{
    I(){
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
}cww;


typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<VI> VVI;
VS wrap(VS v,char c){
    int R=v.size();
    int C=v[0].size();
    VS res(R+2,string(C+2,c));
    for(int i=1;i<=R;i++)
        for(int j=1;j<=C;j++)
            res[i][j]=v[i-1][j-1];
    return res;
}

const int dir8[]={0,1,-1,1,1,0,-1,-1,0};
int main(){
    int R,C,res=0;
    cin>>R>>C;
    VS m(R);
    for(auto &it:m)cin>>it;
    m=wrap(wrap(m,'.'),'W');
    VVI d(R=m.size(),VI(C=m[0].size(),0));
    using P=tuple<int,int>;
    queue<P> que;
    for(int i=0;i<R;i++)
        for(int j=0;j<C;j++)
            if(m[i][j]=='.')
                que.push(P(i,j));
            else if(m[i][j]=='#')
                d[i][j]=-1;
    while(que.size()){
        int r,c;
        tie(r,c)=que.front();que.pop();
        res=max(res,d[r][c]);
        for(int i=0;i<8;i++){
            int nr=r+dir8[i];
            int nc=c+dir8[i+1];
            if(d[nr][nc]==-1){
                d[nr][nc]=d[r][c]+1;
                que.push(P(nr,nc));
            }
        }
    }
    cout<<res<<endl;
    return 0;
}
0