結果

問題 No.424 立体迷路
ユーザー tashikanitashikani
提出日時 2016-09-23 00:30:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,159 bytes
コンパイル時間 822 ms
コンパイル使用メモリ 99,264 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 16:52:21
合計ジャッジ時間 2,013 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MP make_pair
#define MT make_tuple
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

#define CUR cur.first][cur.second
#define NEXT next.first][next.second
#define FAR far.first][far.second

int main() {

	int h, w;
	cin >> h >> w;

	int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	sx--;sy--;
	gx--;gy--;

	VS S(h);
	REP(i, h) cin >> S[i];

	VVI done(h, VI(w, 0));

	queue<PII> que;
	que.push(MP(sx, sy));

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

	while(!que.empty()){
		PII cur = que.front();
		que.pop();

		REP(i, 4){
			PII next = MP(cur.first + dx[i], cur.second + dy[i]);
			if(next.first < 0 || h <= next.first) continue;
			if(next.second < 0 || w <= next.second) continue;

			if(abs(S[CUR] - S[NEXT]) <= 1){
				if(!done[NEXT]){
					que.push(next);
					done[NEXT] = true;
				}
			}

			PII far = MP(next.first + dx[i], next.second + dy[i]);
			if(far.first < 0 || h <= far.first) continue;
			if(far.second < 0 || w <= far.second) continue;

			if(S[CUR] >= S[NEXT] && S[CUR] == S[FAR]){
				if(!done[FAR]){
					que.push(far);
					done[FAR] = true;
				}
			}
		}
	}

//	EACH(d, done){
//		EACH(a, d) cout << a;
//		cout << endl;
//	}

	if(done[gx][gy]) cout << "YES" << endl;
	else cout << "NO" << endl;


	return 0;
}
0