結果

問題 No.402 最も海から遠い場所
ユーザー roarisroaris
提出日時 2019-12-12 21:09:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,703 bytes
コンパイル時間 1,574 ms
コンパイル使用メモリ 170,728 KB
実行使用メモリ 123,388 KB
最終ジャッジ日時 2023-09-07 21:50:00
合計ジャッジ時間 4,920 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,488 KB
testcase_01 AC 2 ms
5,480 KB
testcase_02 AC 2 ms
5,820 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,676 KB
testcase_05 AC 2 ms
5,676 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
5,532 KB
testcase_09 AC 2 ms
5,808 KB
testcase_10 AC 2 ms
5,472 KB
testcase_11 AC 2 ms
5,812 KB
testcase_12 WA -
testcase_13 AC 4 ms
6,444 KB
testcase_14 AC 3 ms
8,284 KB
testcase_15 AC 15 ms
13,552 KB
testcase_16 AC 19 ms
15,988 KB
testcase_17 AC 207 ms
54,192 KB
testcase_18 AC 491 ms
53,920 KB
testcase_19 AC 398 ms
123,388 KB
testcase_20 WA -
testcase_21 AC 346 ms
87,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int H, W;
char S[3100][3100];
int dist[3100][3100];

void bfs() {
    queue<P> q;
    
    for (int i=0; i<H+2; i++) {
        for (int j=0; j<W+2; j++) {
            if (S[i][j]=='.') {
                q.push(P(i, j));
                dist[i][j] = 0;
            }
            else {
                dist[i][j] = -1;
            }
        }
    }
    
    while (q.size()) {
        P p = q.front(); q.pop();
        int cx=p.first, cy=p.second;
        
        for (int i=-1; i<=1; i++) {
            for (int j=-1; j<=1; j++) {
                int nx=cx+i, ny=cy+j;
                
                if (!(0<=nx && nx<H && 0<=ny && ny<W)) {
                    continue;
                }
                
                if (dist[nx][ny]==-1) {
                    dist[nx][ny] = dist[cx][cy]+1;
                    q.push(P(nx, ny));
                }
            }
        }
    }
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    
    cin >> H >> W;
    
    for (int i=0; i<H+2; i++) {
        if (i==0 || i==H+1) {
            for (int j=0; j<W+2; j++) {
                S[i][j] = '.';
            }
        }
        else {
            string Si; cin >> Si;
            
            for (int j=0; j<W+2; j++) {
                if (j==0 || j==W+1) {
                    S[i][j] = '.';
                }
                else {
                    S[i][j] = Si[j-1];
                }
            }
        }
    }
    
    bfs();
    int ans = 0;
    
    for (int i=0; i<H+2; i++) {
        for (int j=0; j<W+2; j++) {
            ans = max(ans, dist[i][j]);
        }
    }
    
    cout << ans << endl;
}
0