結果

問題 No.157 2つの空洞
ユーザー sugim48sugim48
提出日時 2015-02-26 23:30:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,611 bytes
コンパイル時間 2,654 ms
コンパイル使用メモリ 86,284 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 05:10:22
合計ジャッジ時間 1,661 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <fstream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { ll B, T, F, P; };

unsigned MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int UNKO = INT_MAX;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

void dfs(int x, int y, int z, vector<string>& C) {
	C[y][x] = z;
	for (int k = 0; k < 4; k++) {
		int _x = x + dx[k], _y = y + dy[k];
		if (C[_y][_x] == '.') dfs(_x, _y, z, C);
	}
}

int main() {
	int W, H; cin >> W >> H;
	vector<string> C(H);
	for (int i = 0; i < H; i++)
		cin >> C[i];
	for (int y = 0; y < H; y++)
		for (int x = 0; x < W; x++)
			if (C[y][x] == '.') {
				dfs(x, y, 'A', C);
				goto unko;
			}
	unko:;
	for (int y = 0; y < H; y++)
		for (int x = 0; x < W; x++)
			if (C[y][x] == '.')
				dfs(x, y, 'B', C);
	/*for (int y = 0; y < H; y++)
		cout << C[y] << endl;*/
	int mini = INT_MAX;
	for (int y = 0; y < H; y++)
		for (int x = 0; x < W; x++)
			for (int _y = 0; _y < H; _y++)
				for (int _x = 0; _x < W; _x++)
					if (C[y][x] == 'A' && C[_y][_x] == 'B')
						mini = min(mini, abs(x - _x) + abs(y - _y) - 1);
	cout << mini << endl;
}
0