結果

問題 No.424 立体迷路
ユーザー airisairis
提出日時 2016-09-22 23:23:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,488 bytes
コンパイル時間 1,218 ms
コンパイル使用メモリ 145,420 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 16:50:33
合計ジャッジ時間 2,373 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(x, to) for (int x = 0; x < (to); x++)
#define REP(x, a, to) for (int x = (a); x < (to); x++)
#define EPS (1e-14)
#define _PA(x,N) rep(i,N){cout<<x[i]<<" ";}cout<<endl;
#define _PA2(x,H,W) rep(i,(H)){rep(j,(W)){cout<<x[i][j]<<" ";}cout<<endl;}


using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef complex<double> Complex;
typedef vector< vector<int> > Mat;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int h, w;
int sx, sy, gx, gy;
string b[55];
int f[55][55];

char visit[55][55];

void dfs(int y, int x) {
	if (visit[y][x]) return;
	visit[y][x] = 1;
	for (int i = 0; i < 4; i++) {
		int ny = y + dy[i];
		int nx = x + dx[i];
		if (ny < 0 || ny >= h) continue;
		if (nx < 0 || nx >= w) continue;
		if (f[ny][nx] - 1 <= f[y][x] && f[y][x] <= f[ny][nx] + 1) {
			dfs(ny, nx);
		} else if (f[y][x] - f[ny][nx] >= 2) {
			ny += dy[i];
			nx += dx[i];
			if (ny < 0 || ny >= h) continue;
			if (nx < 0 || nx >= w) continue;
			if (f[ny][nx] != f[y][x]) continue;
			dfs(ny, nx);
		}
	}
}

void solve() {
	dfs(sy, sx);
	if (visit[gy][gx]) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}

int main() {
	cin >> h >> w;
	cin >> sx >> sy >> gx >> gy;
	sx--, sy--, gx--, gy--;
	swap(sy, sx);
	swap(gy ,gx);
	for (int i = 0; i < h; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			f[i][j] = b[i][j] - '0';
		}
	}

	solve();
	return 0;
}


0