結果

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

テストケース

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

ソースコード

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 << endl;
}
0