結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-09-02 17:20:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,325 bytes |
| コンパイル時間 | 786 ms |
| コンパイル使用メモリ | 82,884 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-01 20:43:24 |
| 合計ジャッジ時間 | 1,570 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
const int inf = 100100100;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
int h,w;
cin >> w >> h;
char c[h][w];
rep(i,0,h) rep(j,0,w) cin >> c[i][j];
vector< vector<pair<int,int>> > arr;
rep(i,0,h) rep(j,0,w){
if(c[i][j] == '.'){
vector<pair<int,int>> tmp;
vector<pair<int,int>> stk;
stk.push_back(make_pair(i,j));
while(!stk.empty()){
pair<int,int> t = stk.back();
stk.pop_back();
c[t.first][t.second] = '#';
tmp.push_back(make_pair(t.first,t.second));
rep(k,0,4){
int y = t.first + dy[k]; int x = t.second + dx[k];
if(-1 < y && y < h && -1 < x && x < w && c[y][x] == '.'){
stk.push_back(make_pair(y,x));
}
}
}
arr.push_back(tmp);
}
}
int ans = inf;
for(auto a: arr[0]){
for(auto b: arr[1]){
ans = min(ans,abs(a.first - b.first) + abs(a.second - b.second));
}
}
cout << ans-1 << endl;
}