結果

問題 No.424 立体迷路
ユーザー aaaaaa
提出日時 2018-08-19 17:36:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,410 bytes
コンパイル時間 1,073 ms
コンパイル使用メモリ 103,292 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 17:05:25
合計ジャッジ時間 2,081 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>

using namespace std;
int i, j, k;
int h, w, sx, sy, gx, gy;
vector<string>b;
vector<vector<bool>>matrix(100, vector<bool>(100, false));

int func(int x, int y) {
	/*
	cout << "x->" << x << " y->" << y << endl;
	for (int i = 0; i <= h; i++) {
		for (int j = 0; j <= w; j++) {
			cout << matrix[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl; cout << endl;
	*/

	if (x == gx && y == gy) {
		cout << "YES" << endl;
		getchar();
		getchar();
		exit(0);
		//return 0;
	}

	int taka = (int)b[y][x] - 48;

	if (y - 1 >= 0 && matrix[y - 1][x] == false && abs(taka - ((int)b[y - 1][x] - 48)) <= 1) {
		matrix[y - 1][x] = true;
		func(x, y - 1);
	}
	if (y + 1 <= h && matrix[y + 1][x] == false && abs(taka - ((int)b[y + 1][x] - 48)) <= 1) {
		matrix[y + 1][x] = true;
		func(x, y + 1);
	}
	if (x + 1 <= w && matrix[y][x + 1] == false && abs(taka - ((int)b[y][x + 1] - 48)) <= 1) {
		matrix[y][x + 1] = true;
		func(x + 1, y);
	}
	if (x - 1 >= 0 && matrix[y][x - 1] == false && abs(taka - ((int)b[y][x - 1] - 48)) <= 1) {
		matrix[y][x - 1] = true;
		func(x - 1, y);
	}

	if (y - 2 >= 0 && matrix[y - 2][x] == false && (int)b[y - 1][x] - 48 < taka && taka - ((int)b[y - 2][x] - 48) == 0) {
		matrix[y - 2][x] = true;
		func(x, y - 2);
	}
	if (y + 2 <= h && matrix[y + 2][x] == false && (int)b[y + 1][x] - 48  < taka && taka - ((int)b[y + 2][x] - 48) == 0) {
		matrix[y + 2][x] = true;
		func(x, y + 2);
	}
	if (x + 2 <= w && matrix[y][x + 2] == false && (int)b[y][x + 1] - 48  < taka &&  taka - ((int)b[y][x + 2] - 48) == 0) {
		matrix[y][x + 2] = true;
		func(x + 2, y);
	}
	if (x - 2 >= 0 && matrix[y][x - 2] == false && (int)b[y][x - 1] - 48  < taka &&  taka - ((int)b[y][x - 2] - 48) == 0) {
		matrix[y][x - 2] = true;
		func(x - 2, y);
	}



	return 0;
}

int main() {
	

	cin >> h >> w;
	//cin >> w >> h;
	//cin >> sx >> sy >> gx >> gy;
	cin >> sy >> sx >> gy >> gx;

	h--; w--;
	sx--; sy--; gx--; gy--;

	for (i = 0; i <= h; i++) {
	//for (i = 0; i <= w; i++) {
		string st;
		cin >> st;
		b.push_back(st);
	}

	matrix[sy][sx] = true;

	//func(sy, sx);
	func(sx, sy);

	cout << "NO" << endl;




	getchar();
	getchar();
	return 0;
}
0