結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
alpha_virginis
|
| 提出日時 | 2015-07-18 10:03:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,045 bytes |
| コンパイル時間 | 1,277 ms |
| コンパイル使用メモリ | 159,228 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-08 10:07:25 |
| 合計ジャッジ時間 | 1,929 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 13 WA * 3 |
ソースコード
#include <bits/stdc++.h>
int W, H;
std::string str[32];
void dfs(int x, int y) {
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
for(int i = 0; i < 4; ++i) {
int nx = x + dx[i];
int ny = y + dy[i];
if( 0 <= nx and nx < W and 0 <= ny and ny < H ) {
if( str[ny][nx] == '.' ) {
str[ny][nx] = '1';
dfs(nx, ny);
}
}
}
return;
}
int main() {
std::cin >> W >> H;
for(int i = 0; i < H; ++i) {
std::cin >> str[i];
}
for(int i = 0; i < H; ++i) {
for(int j = 0; j < W; ++j) {
if( str[i][j] == '.' ) {
dfs(j, i);
goto label_1;
}
}
}
label_1:;
int ans = 100000;
for(int x1 = 0; x1 < W; ++x1) {
for(int y1 = 0; y1 < H; ++y1) {
for(int x2 = 0; x2 < W; ++x2) {
for(int y2 = 0; y2 < H; ++y2) {
if( str[y1][x1] == '.' and str[y2][x2] == '1' ) {
ans = std::min(ans, abs(x2 - x1) + abs(y2 - y1) - 1);
}
}
}
}
}
std::cout << ans << std::endl;
return 0;
}
alpha_virginis