結果

問題 No.424 立体迷路
ユーザー femtofemto
提出日時 2016-09-22 22:39:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,268 bytes
コンパイル時間 981 ms
コンパイル使用メモリ 86,780 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 16:44:00
合計ジャッジ時間 2,054 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <queue>
using namespace std;

int h, w, sx, sy, gx, gy;
int b[50][50];
bool visited[50][50];
typedef pair<int, int> P;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };

bool in(int x, int y) {
	return 0 <= x && x < w && 0 <= y && y < h;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

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

	queue<P> q;
	q.push(P(sx, sy));
	visited[sy][sx] = true;
	while(q.size()) {
		int x = q.front().first, y = q.front().second;
		q.pop();
		for(int i = 0; i < 4; i++) {
			int nx = x + dx[i], ny = y + dy[i];
			if(in(nx, ny) && !visited[ny][nx] && abs(b[ny][nx] - b[y][x]) <= 1) {
				visited[ny][nx] = true;
				q.push(P(nx, ny));
			}
			int nnx = nx + dx[i], nny = ny + dy[i];
			if(in(nnx, nny) && !visited[nny][nnx] && b[nny][nnx] == b[y][x] && b[y][x] > b[ny][nx]) {
				visited[nny][nnx] = true;
				q.push(P(nnx, nny));
			}
		}
	}

	if(visited[gy][gx]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}
0