結果

問題 No.2412 YOU Grow Bigger!
ユーザー kotatsugamekotatsugame
提出日時 2023-08-11 21:57:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,146 bytes
コンパイル時間 941 ms
コンパイル使用メモリ 84,136 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 12:53:09
合計ジャッジ時間 2,597 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 109 ms
5,376 KB
testcase_04 AC 110 ms
5,376 KB
testcase_05 AC 78 ms
5,376 KB
testcase_06 AC 102 ms
5,376 KB
testcase_07 AC 109 ms
5,376 KB
testcase_08 AC 99 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 6 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 2 ms
5,376 KB
testcase_18 AC 15 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 5 ms
5,376 KB
testcase_23 AC 15 ms
5,376 KB
testcase_24 AC 49 ms
5,376 KB
testcase_25 WA -
testcase_26 AC 3 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 8 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<queue>
#include<cassert>
using namespace std;
int H,W;
vector<string>S;
vector<vector<int> >vis;
const int d[5]={0,1,0,-1};
bool f()
{
	for(int i=1;i<H-1;i++)for(int j=1;j<W-1;j++)
	{
		bool out=false;
		for(int x=i-1;x<=i+1;x++)for(int y=j-1;y<=j+1;y++)
		{
			if(S[x][y]=='#')out=true;
		}
		vis[i][j]=out?0:1;
	}
	queue<pair<int,int> >Q;
	Q.push(make_pair(1,1));
	vis[1][1]=2;
	while(!Q.empty())
	{
		int x=Q.front().first,y=Q.front().second;
		Q.pop();
		for(int r=0;r<4;r++)
		{
			int tx=x+d[r],ty=y+d[r+1];
			if(vis[tx][ty]!=1)continue;
			vis[tx][ty]=2;
			Q.push(make_pair(tx,ty));
		}
	}
	return vis[H-2][W-2]!=2;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>H>>W;
	S=vector<string>(H);
	vis=vector<vector<int> >(H,vector<int>(W,0));
	for(int i=0;i<H;i++)cin>>S[i];
	if(f())cout<<0<<endl;
	else
	{
		bool fn=false;
		for(int i=0;!fn&&i<H;i++)for(int j=0;j<W;j++)
		{
			if(i<3&&j<3)continue;
			if(H-i<=3&&W-j<=3)continue;
			if(S[i][j]=='#')continue;
			S[i][j]='#';
			if(f())
			{
				fn=true;
				break;
			}
			S[i][j]='.';
		}
		cout<<(fn?1:2)<<endl;
	}
}
0