結果

問題 No.2412 YOU Grow Bigger!
ユーザー kotatsugamekotatsugame
提出日時 2023-08-11 21:58:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 137 ms / 6,000 ms
コード長 1,125 bytes
コンパイル時間 905 ms
コンパイル使用メモリ 84,352 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 06:34:19
合計ジャッジ時間 2,720 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 137 ms
6,944 KB
testcase_04 AC 137 ms
6,940 KB
testcase_05 AC 94 ms
6,940 KB
testcase_06 AC 122 ms
6,944 KB
testcase_07 AC 136 ms
6,940 KB
testcase_08 AC 123 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 6 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 17 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 4 ms
6,940 KB
testcase_22 AC 6 ms
6,944 KB
testcase_23 AC 29 ms
6,940 KB
testcase_24 AC 56 ms
6,940 KB
testcase_25 AC 28 ms
6,944 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 9 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<queue>
#include<cassert>
using namespace std;
int H,W;
vector<string>S;
vector<vector<int> >vis;
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 tx=x-1;tx<=x+1;tx++)for(int ty=y-1;ty<=y+1;ty++)
		{
			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