結果

問題 No.157 2つの空洞
ユーザー CleyLCleyL
提出日時 2022-02-08 16:46:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,399 bytes
コンパイル時間 694 ms
コンパイル使用メモリ 75,444 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 16:24:00
合計ジャッジ時間 1,622 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define mkp make_pair
P ar4[4] = {mkp(0,1),mkp(0,-1),mkp(1,0),mkp(-1,0)};
vector<vector<char>> A(21,vector<char>(21));
vector<P> X,Y;
void dfs(int y,int x,int v){
    A[y][x] = '#';
    if(v==0)X.push_back({x,y});
    else Y.push_back({x,y});
    for(int i = 0; 4 > i; i++){
        if(A[y+ar4[i].first][x+ar4[i].second] == '.'){
            dfs(y+ar4[i].first,x+ar4[i].second,v);
        }
    }
}
int main(){
    int n,m;cin>>n>>m;
    
    for(int i = 0; m > i; i++){
        for(int j = 0; n > j; j++){
            cin>>A[i][j];
        }
    }
    for(int i = 0; m > i; i++){
        for(int j = 0; n > j; j++){
            if(A[i][j] == '.' && !X.size()){
                dfs(i,j,0);
            }else if(A[i][j] == '.'){
                dfs(i,j,1);
            }
        }
    }
    // cout << X.size() << " " << Y.size() << endl;
    // for(int i = 0; X.size() > i; i++){
    //   cout << X[i].first << " " << X[i].second << endl;
    // }
    // cout << endl;
    // for(int i = 0; Y.size() > i; i++){
    //   cout << Y[i].first << " " << Y[i].second << endl;
    // }
    ll mn = 200;
    for(int i = 0; X.size() > i; i++){
      for(int j = 0; Y.size() > j; j++){
        mn = min(mn,abs(X[i].first-Y[j].first)+abs(X[i].second-Y[j].second));
      }
    }
    cout << mn-1 << endl;
}
0