結果

問題 No.402 最も海から遠い場所
ユーザー ShibuyapShibuyap
提出日時 2020-01-29 17:27:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,638 bytes
コンパイル時間 2,910 ms
コンパイル使用メモリ 173,808 KB
実行使用メモリ 129,636 KB
最終ジャッジ日時 2023-10-14 06:27:54
合計ジャッジ時間 6,451 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,348 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 458 ms
129,636 KB
testcase_20 AC 411 ms
56,576 KB
testcase_21 AC 412 ms
93,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int h, w;
    cin >> h >> w;
    string s[h+2];
    rep(i,h+2){
        if(i == 0 || i == h + 1){
            rep(j,w+2)s[i] += '.';
        }else{
            string ss; cin >> ss;
            s[i] = '.' + ss + '.';
        }
    }

    int f[h+2][w+2];
    rep(i,h+2){
        rep(j,w+2){
            if(i == 0 || j == 0 || i == h+1 || j == w+1){
                f[i][j] = 0;
            }else{
                f[i][j] = 1001001;
            }
            
        }
    }

    queue<P> que;
    srep(i,1,h+1){
        srep(j,1,w+1){
            if(s[i][j] == '.'){
                f[i][j] = 0;
                que.push(P(i,j));
            }else{
                if(i == 1 || i == h || j == 1 || j == w){
                    f[i][j] = 1;
                    que.push(P(i,j));
                }
            }
        }
    }

    int dx[4] = {-1, 1, 0, 0};
    int dy[4] = {0, 0, -1, 1};

    while(que.size()){
        int x = que.front().first;
        int y = que.front().second;
        que.pop();
        rep(k,4){
            if(f[x+dx[k]][y+dy[k]] > f[x][y] + 1){
                f[x+dx[k]][y+dy[k]] = f[x][y] + 1;
                que.push(P(x+dx[k], y+dy[k]));
            }
        }
    }

    int ans = 0;

    rep(i,h+2)rep(j,w+2)ans = max(ans, f[i][j]);

    cout << ans << endl;
    return 0;
}
 
 
0