結果

問題 No.424 立体迷路
ユーザー matsukin1111matsukin1111
提出日時 2019-04-29 11:55:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,977 bytes
コンパイル時間 853 ms
コンパイル使用メモリ 96,180 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 17:06:45
合計ジャッジ時間 1,949 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX/2
using namespace std;
using ll = long long;
using R = double;
using Data = pair<ll, vector<int>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 50;
struct edge { ll from; ll to; ll cost; };

int h, w;
int sx, sy, gx, gy;
vector<string>mp(55);
int memo[55][55];
int used[55][55];

int check1(int x1,int y1,int x2,int y2) {
	int h1 = mp[y1][x1] - '0';
	int h2 = mp[y2][x2] - '0';
	if (abs(x1 - x2)+abs(y1 - y2) == 1) {
		if (abs(h1 - h2) <= 1)return true;
	}else {
		if (abs(x1 - x2) == 2) {
			int h3 = mp[y2][(x1+x2)/2] - '0';
			if (h1 == h2 && h1 > h3)return true;
		}
		else {
			int h4 = mp[(y1+y2)/2][x2] - '0';
			if (h1 == h2 && h1 > h4)return true;
		}
	}
	return false;
}

int dfs(int x,int y) {
	if (x == gx && y == gy)return true;
	if (memo[y][x] != -1)return memo[y][x];

	int dx[8] = {-1,0,1,0,-2,0,2,0};
	int dy[8] = {0,1,0,-1,0,2,0,-2};
	int ret = 0;
	rep(i, 0, 8) {
		int x_ = x + dx[i];
		int y_ = y + dy[i];
		if (0 <= y_ && y_ <= h - 1 && 0 <= x_ && x_ <= w - 1 && used[y_][x_] == 0) {
			if (check1(x, y, x_, y_)) {
				used[y_][x_] = 1;
				if (dfs(x_, y_))ret = 1;
			}
		}
	}
	return memo[y][x] = ret;
}

int main() {
	cin >> h >> w;
	cin >> sx >> sy >> gx >> gy;
	sx--, sy--, gx--, gy--;
	swap(sx, sy);
	swap(gx, gy);

	rep(i, 0, h) {
		cin >> mp[i];
	}

	memset(memo, -1, sizeof(memo));

	used[sy][sx] = 1;
	if (dfs(sx,sy))cout << "YES" << endl;
	else cout << "NO" << endl;


	return 0;
}
0