結果

問題 No.402 最も海から遠い場所
ユーザー btkbtk
提出日時 2016-07-27 15:46:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 578 ms / 3,000 ms
コード長 1,216 bytes
コンパイル時間 2,068 ms
コンパイル使用メモリ 177,564 KB
実行使用メモリ 121,360 KB
最終ジャッジ日時 2024-04-24 10:22:06
合計ジャッジ時間 5,116 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 11 ms
5,632 KB
testcase_16 AC 15 ms
6,400 KB
testcase_17 AC 179 ms
42,752 KB
testcase_18 AC 578 ms
51,840 KB
testcase_19 AC 278 ms
121,360 KB
testcase_20 AC 357 ms
48,000 KB
testcase_21 AC 260 ms
84,836 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