結果

問題 No.157 2つの空洞
ユーザー 沙耶花沙耶花
提出日時 2021-11-02 21:59:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 999 bytes
コンパイル時間 4,729 ms
コンパイル使用メモリ 260,800 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 08:42:48
合計ジャッジ時間 5,238 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001


int main(){	
	
	int w,h;
	cin>>w>>h;
	
	vector<string> s(h);
	rep(i,h)cin>>s[i];
	
	vector dis(h,vector<int>(w,Inf));
	
	vector<int> dx = {0,0,1,-1},dy = {1,-1,0,0};
	deque<pair<int,int>> D;
	rep(i,h){
		rep(j,w){
			if(s[i][j]=='.'){
				dis[i][j] = 0;
				D.emplace_back(i,j);
				goto L;
			}
		}
	}
	L:;
	while(D.size()>0){
		int y = D.back().first,x = D.back().second;
		D.pop_back();
		rep(i,4){
			int yy = y+dy[i],xx = x+dx[i];
			if(yy<0||yy>=h||xx<0||xx>=w)continue;
			int c = 0;
			if(s[yy][xx]=='#')c++;
			if(dis[yy][xx]<=dis[y][x]+c)continue;
			dis[yy][xx] = dis[y][x]+c;
			if(c==0)D.emplace_back(yy,xx);
			else D.emplace_front(yy,xx);
		}
	}
	
	int ans = 0;
	rep(i,h){
		rep(j,w){
			if(s[i][j]=='.'&&dis[i][j]!=0)ans = dis[i][j];
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
	
}
0