結果

問題 No.402 最も海から遠い場所
ユーザー tossytossy
提出日時 2016-07-22 23:03:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 521 ms / 3,000 ms
コード長 1,658 bytes
コンパイル時間 763 ms
コンパイル使用メモリ 95,956 KB
実行使用メモリ 147,520 KB
最終ジャッジ日時 2024-04-24 05:55:26
合計ジャッジ時間 4,332 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
39,040 KB
testcase_01 AC 15 ms
38,912 KB
testcase_02 AC 16 ms
39,080 KB
testcase_03 AC 14 ms
38,912 KB
testcase_04 AC 15 ms
38,944 KB
testcase_05 AC 15 ms
38,968 KB
testcase_06 AC 16 ms
38,968 KB
testcase_07 AC 14 ms
38,996 KB
testcase_08 AC 15 ms
38,856 KB
testcase_09 AC 15 ms
38,912 KB
testcase_10 AC 15 ms
39,012 KB
testcase_11 AC 15 ms
39,008 KB
testcase_12 AC 15 ms
38,816 KB
testcase_13 AC 18 ms
39,196 KB
testcase_14 AC 16 ms
38,916 KB
testcase_15 AC 28 ms
40,336 KB
testcase_16 AC 32 ms
40,960 KB
testcase_17 AC 232 ms
65,404 KB
testcase_18 AC 521 ms
44,696 KB
testcase_19 AC 418 ms
147,520 KB
testcase_20 AC 348 ms
39,052 KB
testcase_21 AC 361 ms
94,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define INF 1<<30

typedef pair<int, pair<int, int> > P;

int mat[3005][3005];

int main(){
    int h,w;
    cin>>h>>w;

    fill(mat[0], mat[3005], INF);

    queue<P> que;
    char c[3005];
    rep(i,h){
        scanf("%s", c);
        rep(j,w){
            if(c[j]=='.'){
                mat[i][j] = 0;
                que.push(mp(0,mp(i,j)));
            }
        }
    }

    // insert out of map
    rep(i,h+2){ que.push(mp(0,mp(i-1, -1))); que.push(mp(0,mp(i-1, w)));}
    rep(i,w  ){ que.push(mp(0,mp(-1, i))); que.push(mp(0,mp(h, i)));}

    while(!que.empty()){
        const int di[] = {-1,1,0}, dj[]={0,-1,1};
        P p = que.front(); que.pop();
        int nl = p.first+1;
        int i = p.second.first, j = p.second.second;
        rep(ri, 3) rep(rj,3){
            int ni = i+di[ri], nj = j+dj[rj];
            if(ni<0 || ni>=h || nj<0 || nj>=w) continue;

            if(mat[ni][nj] > nl){
                mat[ni][nj] = nl;
                que.push(mp(nl, mp(ni,nj)));
            }
        }
    }

    //rep(i,h){rep(j,w) printf("%2d", mat[i][j]); printf("\n");}

    int res=0;
    rep(i,h)rep(j,w) res = max(res, mat[i][j]);

    cout<<res<<endl;

    return 0;
}
0