結果

問題 No.2412 YOU Grow Bigger!
ユーザー square1001square1001
提出日時 2023-08-11 21:59:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,403 bytes
コンパイル時間 1,025 ms
コンパイル使用メモリ 85,996 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-11 21:59:23
合計ジャッジ時間 4,442 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 215 ms
4,376 KB
testcase_04 AC 223 ms
4,376 KB
testcase_05 AC 168 ms
4,380 KB
testcase_06 AC 196 ms
4,376 KB
testcase_07 AC 221 ms
4,380 KB
testcase_08 AC 170 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 62 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 107 ms
4,380 KB
testcase_14 AC 68 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 70 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 WA -
testcase_22 AC 122 ms
4,380 KB
testcase_23 AC 54 ms
4,376 KB
testcase_24 AC 118 ms
4,376 KB
testcase_25 WA -
testcase_26 AC 57 ms
4,376 KB
testcase_27 AC 37 ms
4,376 KB
testcase_28 AC 74 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

const vector<int> dx = { 0, 1, 0, -1 };
const vector<int> dy = { 1, 0, -1, 0 };

bool reachable(int H, int W, const vector<string>& S) {
	vector<vector<bool> > flag(H - 2, vector<bool>(W - 2, true));
	for (int i = 0; i < H - 2; i++) {
		for (int j = 0; j < W - 2; j++) {
			for (int k = 0; k < 3; k++) {
				for (int l = 0; l < 3; l++) {
					if (S[i + k][j + l] == '#') {
						flag[i][j] = false;
					}
				}
			}
		}
	}
	vector<vector<bool> > vis(H - 2, vector<bool>(W - 2, false));
	auto dfs = [&](auto& dfs, int x, int y) -> void {
		vis[x][y] = true;
		for (int i = 0; i < 4; i++) {
			int tx = x + dx[i];
			int ty = y + dy[i];
			if (0 <= tx && tx < H - 2 && 0 <= ty && ty < W - 2 && flag[tx][ty] && !vis[tx][ty]) {
				dfs(dfs, tx, ty);
			}
		}
	};
	dfs(dfs, 0, 0);
	return vis[H - 3][W - 3];
}

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}
	if (!reachable(H, W, S)) {
		cout << 0 << endl;
	}
	else {
		bool flag = false;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (S[i][j] == '.' && !(i < 3 && j < 3) && !(i >= H - 3 && j >= W - 3)) {
					S[i][j] = '#';
					if (!reachable(H, W, S)) {
						flag = true;
					}
					S[i][j] = '.';
				}
			}
		}
		cout << (flag ? 1 : 2) << endl;
	}
	return 0;
}
0