結果

問題 No.157 2つの空洞
ユーザー BantakoBantako
提出日時 2017-08-08 21:22:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,127 bytes
コンパイル時間 1,368 ms
コンパイル使用メモリ 164,796 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 05:16:57
合計ジャッジ時間 1,958 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = 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