結果

問題 No.2412 YOU Grow Bigger!
ユーザー shobonvipshobonvip
提出日時 2023-08-11 22:12:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 243 ms / 6,000 ms
コード長 2,458 bytes
コンパイル時間 3,931 ms
コンパイル使用メモリ 272,096 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 06:36:08
合計ジャッジ時間 6,300 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 1 ms
6,816 KB
testcase_03 AC 233 ms
6,816 KB
testcase_04 AC 238 ms
6,940 KB
testcase_05 AC 192 ms
6,944 KB
testcase_06 AC 215 ms
6,940 KB
testcase_07 AC 243 ms
6,940 KB
testcase_08 AC 190 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 6 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 10 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 26 ms
6,944 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 6 ms
6,940 KB
testcase_22 AC 9 ms
6,940 KB
testcase_23 AC 58 ms
6,940 KB
testcase_24 AC 108 ms
6,940 KB
testcase_25 AC 45 ms
6,940 KB
testcase_26 AC 5 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 13 ms
6,944 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

bool solve(int h, int w, vector<vector<char>> &c){
	vector<vector<bool>> tansaku(h-2, vector<bool>(w-2));
	tansaku[0][0] = true;
	rep(i,0,3){
		rep(j,0,3){
			if (c[i][j] == '#') return false;
		}
	}
	vector<vector<bool>> good(h-2, vector<bool>(w-2));
	rep(x,0,h-2){
		rep(y,0,w-2){
			bool mode = true;
			rep(xx,x,x+3){
				rep(yy,y,y+3){
					if (c[xx][yy] == '#'){
						mode = false;
					}
				}
			}
			good[x][y] = mode;
		}
	}
	vector<pair<int,int>> mada = {pair(0, 0)};
	while(!mada.empty()){
		auto [i, j] = mada.back();
		mada.pop_back();
		rep(x,i-1,i+2){
			rep(y,j-1,j+2){
				if (!(0 <= x && x < h-2)) continue;
				if (!(0 <= y && y < w-2)) continue;
				if (tansaku[x][y]) continue;
				if (!good[x][y]) continue;
				tansaku[x][y] = true;
				mada.push_back(pair(x, y));
			}
		}
	}
	return tansaku[h-3][w-3];
}

int main(){
	int h, w; cin >> h >> w;
	vector<vector<char>> c(h, vector<char>(w));
	rep(i,0,h){
		rep(j,0,w){
			cin >> c[i][j];
		}
	}
	if (!solve(h, w, c)){
		cout << 0 << '\n';
		return 0;
	}
	rep(i,0,h-1){
		rep(j,0,w-1){
			vector<vector<char>> cc = c;
			cc[i][j] = '#';
			bool mode = true;
			rep(i,0,3){
				rep(j,0,3){
					if (cc[i][j] == '#') mode = false;
				}
			}
			rep(i,h-3,h){
				rep(j,w-3,w){
					if (cc[i][j] == '#') mode = false;
				}
			}
			if (!mode) continue;
			if (!solve(h, w, cc)){
				cout << 1 << '\n';
				return 0;
			}
		}
	}
	cout << 2 << '\n';
}

0