結果
問題 | No.157 2つの空洞 |
ユーザー |
![]() |
提出日時 | 2015-02-26 23:30:04 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,611 bytes |
コンパイル時間 | 754 ms |
コンパイル使用メモリ | 88,540 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-23 23:53:21 |
合計ジャッジ時間 | 1,826 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
#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;}