結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 50 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 91 ms
4,376 KB
testcase_14 AC 58 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 56 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 WA -
testcase_22 AC 84 ms
4,380 KB
testcase_23 AC 47 ms
4,376 KB
testcase_24 AC 102 ms
4,376 KB
testcase_25 WA -
testcase_26 AC 49 ms
4,376 KB
testcase_27 AC 32 ms
4,376 KB
testcase_28 AC 61 ms
4,508 KB
testcase_29 AC 1 ms
4,384 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 : 1) << endl;
	}
	return 0;
}
0