結果

問題 No.157 2つの空洞
ユーザー tabataba
提出日時 2017-05-20 07:42:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,527 bytes
コンパイル時間 1,644 ms
コンパイル使用メモリ 145,360 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 03:51:57
合計ジャッジ時間 2,525 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <random>
#include <vector>
#include <algorithm>
#include <array>
#include <functional>
#include <utility>
#include <regex>
#include <tuple>
#include <map>
#include <set>
#include <iostream>

using namespace std;

int main(){
	int h,w;
	-scanf("%d%d",&w,&h);
	vector<string> c(h);
	vector<array<int,2>> a,b,q;
	vector<int> f(w*h,0x7fffffff);
	for(int y=0;y<h;y++){
		cin>>c[y];
		for(int x=0;x<w;x++){
			if(c[y][x]=='.'){
				a.push_back(array<int,2>({x,y}));
			}
		}
	}
	b.push_back(a.back());
	q.push_back(a.back());
	a.pop_back();
	while(q.size()){
		int cnt=0;
		array<int,2> s=q[q.size()-1];
		s[0]--;
		auto it=find(a.begin(),a.end(),s);
		s[0]++;
		if(it!=a.end()){
			b.push_back(*it);
			q.push_back(*it);
			a.erase(it);
			cnt++;
		}
		s=q[q.size()-1];
		s[0]++;
		it=find(a.begin(),a.end(),s);
		s[0]--;
		if(it!=a.end()){
			b.push_back(*it);
			q.push_back(*it);
			a.erase(it);
			cnt++;
		}
		s=q[q.size()-1];
		s[1]--;
		it=find(a.begin(),a.end(),s);
		s[1]++;
		if(it!=a.end()){
			b.push_back(*it);
			q.push_back(*it);
			a.erase(it);
			cnt++;
		}
		s=q[q.size()-1];
		s[1]++;
		it=find(a.begin(),a.end(),s);
		s[1]--;
		if(it!=a.end()){
			b.push_back(*it);
			q.push_back(*it);
			a.erase(it);
			cnt++;
		}
		if(cnt==0)
			q.pop_back();
	}
	int manhattan_min=0x7fffffff;
	for(auto i:a){
		for(auto j:b){
			manhattan_min=min(manhattan_min,abs(i[0]-j[0])+abs(i[1]-j[1])-1);
		}
	}
	cout<<manhattan_min<<endl;
	return 0;
}
0