結果

問題 No.2412 YOU Grow Bigger!
ユーザー 沙耶花沙耶花
提出日時 2023-08-11 22:29:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,436 bytes
コンパイル時間 4,556 ms
コンパイル使用メモリ 267,060 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 13:30:46
合計ジャッジ時間 5,433 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 WA -
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 WA -
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


int main(){
	
	int h,w;
	cin>>h>>w;
	
	vector<string> s(h);
	rep(i,h)cin>>s[i];
	
	vector d(h,vector<int>(w,Inf32));
	deque<pair<int,int>> D;
	for(int i=h-3;i<h;i++){
		rep(j,w-3){
			if(s[i][j]=='#'){
				d[i][j] = 0;
				D.emplace_back(i,j);
			}
			else{
				d[i][j] = 1;
				D.emplace_front(i,j);
			}
		}
	}
	for(int i=3;i<h;i++){
		rep(j,3){
			if(d[i][j]!=Inf32)continue;
			if(s[i][j]=='#'){
				d[i][j] = 0;
				D.emplace_back(i,j);
			}
			else{
				d[i][j] = 1;
				D.emplace_front(i,j);
			}
		}
	}
	while(D.size()>0){
		int x = D.back().first,y = D.back().second;
		D.pop_back();
		for(int i=-3;i<=3;i++){
			for(int j=-3;j<=3;j++){
				int xx = x+i,yy = y+j;
				if(xx<0||xx>=h||yy<0||yy>=w)continue;
				int cost = d[x][y];
				if(s[xx][yy]=='.')cost++;
				if(xx<3&&yy<3)continue;
				if(xx>=h-3&&yy>=w-3)continue;
				if(d[xx][yy]<=cost)continue;
				d[xx][yy] = cost;
				if(s[xx][yy]=='.'){
					D.emplace_front(xx,yy);
				}
				else D.emplace_back(xx,yy);
			}
		}
	}
	int ans = Inf32;
	rep(i,h){
		for(int j=w-3;j<w;j++){
			
			ans =min(ans,d[i][j]);
		}
	}
	rep(i,3){
		for(int j=3;j<w;j++){
			ans = min(ans,d[i][j]);
		}
	}
	cout<<ans<<endl;
	
	
	return 0;
}
0