結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
IJMP320
|
| 提出日時 | 2015-02-27 00:35:46 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 995 bytes |
| コンパイル時間 | 1,356 ms |
| コンパイル使用メモリ | 161,092 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-23 21:55:35 |
| 合計ジャッジ時間 | 2,124 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | scanf("%s", c[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pint;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 100000000;
const int dx[4]={0,1,0,-1}, dy[4]={-1,0,1,0};
struct P{int x;int y;P(int X=0,int Y=0){x=X;y=Y;}};
int W,H;
char c[22][22];
vector<P> cave1;
vector<P> cave2;
bool sec = false;
void dfs(int x, int y) {
c[y][x] = '#';
if(!sec) cave1.push_back(P(x,y));
else cave2.push_back(P(x,y));
rep(i,4) {
int nx = x + dx[i];
int ny = y + dy[i];
if(nx >= 0 && nx < W && ny >= 0 && ny < H) {
if(c[ny][nx] == '.') dfs(nx, ny);
}
}
return;
}
int main() {
cin >> W >> H;
rep(i,H) {
scanf("%s", c[i]);
}
rep(y,H) {
rep(x,W) {
if(c[y][x] == '.') {
dfs(x, y);
sec = true;
}
}
}
int ans=INF;
int siz1 = cave1.size();
int siz2 = cave2.size();
rep(i,siz1) {
rep(j,siz2) {
ans = min(ans, abs(cave1[i].x - cave2[j].x) + abs(cave1[i].y - cave2[j].y));
}
}
printf("%d\n",ans-1);
return 0;
}
IJMP320