結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
tetsuzuki1115
|
| 提出日時 | 2018-02-25 15:36:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,518 bytes |
| コンパイル時間 | 887 ms |
| コンパイル使用メモリ | 96,148 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-14 04:03:58 |
| 合計ジャッジ時間 | 1,656 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;
long long MOD = 1000000007;
struct Point {
Point(){};
Point( int a, int b ) { x = a; y = b; }
int x;
int y;
};
int dist( Point p1, Point p2 ) {
return abs(p1.x-p2.x) + abs(p1.y-p2.y);
}
vector<string> V;
vector< vector<Point> > P(2);
int W,H;
int dir[4][2] = { {1,0}, {0,1}, {-1,0}, {0,-1} };
bool isOK( int x, int y ) {
return x >= 0 && y >= 0 && x < W && y < H;
}
void func( int a, int x, int y ) {
// cout << a << " " << x << " " << y << endl;
Point p(x,y);
P[a].push_back(p);
V[y][x] = '#';
for ( int i = 0; i < 4; i++ ) {
int nx = x + dir[i][0];
int ny = y + dir[i][1];
if ( isOK(nx,ny) && V[ny][nx] != '#' ) {
func(a,nx,ny);
}
}
}
int main() {
cin >> W >> H;
V.resize(H);
for ( int i = 0; i < H; i++ ) {
cin >> V[i];
}
int a = 0;
for ( int y = 0; y < H; y++ ) {
for ( int x = 0; x < W; x++ ) {
if ( V[y][x] != '#' ) {
func(a,x,y);
a++;
}
}
}
int ans = INT_MAX;
for ( int i = 0; i < P[0].size(); i++ ) {
for ( int j = 0; j < P[1].size(); j++ ) {
ans = min( ans, dist( P[0][i], P[1][j] )-1 );
}
}
cout << ans << endl;
return 0;
}
tetsuzuki1115