結果

問題 No.157 2つの空洞
ユーザー BantakoBantako
提出日時 2017-08-08 21:01:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,130 bytes
コンパイル時間 1,326 ms
コンパイル使用メモリ 165,348 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 05:16:47
合計ジャッジ時間 1,969 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 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 WA -
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 9;//1e9
int MOD = 1e9+7;
char C[20][21];
int dist[20][20];
int H,W;
void update(int y,int x){
    dist[y][x] = 0;
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            dist[i][j] = min(dist[i][j],abs(i-y)+abs(j-x));
        }
    }
}
void dfs(int y,int x){
    if(y == -1 || y == H || x == -1 || x == W)return;
    if(C[y][x] == '#')return;
    C[y][x] = '#';
    update(y,x);
    int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
    for(int k = 0;k < 4;k++)dfs(y+dy[k],x+dx[k]);
}
main(){
    fill(dist[0],dist[20],INF);
    cin >> W >> H;
    for(int i = 0;i < H;i++)cin >> C[i];
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            if(C[i][j] == '.'){
                dfs(i,j);
                goto breakloop;
            }
        }
    }
    breakloop:
    int mindist = INF;
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
//            printf("%d%c",dist[i][j],j==W-1?'\n':' ');
            if(C[i][j] == '.')mindist = min(mindist,dist[i][j]); 
        }
    }
    cout << mindist-1 << endl;
}
0