結果

問題 No.424 立体迷路
ユーザー JotaroJotaro
提出日時 2017-02-14 15:33:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 3,521 bytes
コンパイル時間 701 ms
コンパイル使用メモリ 87,592 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 17:00:52
合計ジャッジ時間 1,822 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

	//include
//------------------------------------------
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#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 <stack>
#include <ctime>
#include <queue>
using namespace std;
 
//conversion
//------------------------------------------
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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define WHITE 0
#define BLACK 1
#define INFTY 1000000000
#define MAX 200000

int maze[500][500];
int v[500][500];
int h,w;
int sx,sy,gx,gy;

void dfs(int y, int x){
	//mark as visited
	// cout << x << y <<  ":" << maze[y][x] << endl;
	v[y][x] = BLACK;
	//tobikoe
	if(x >= 2 && maze[y][x]==maze[y][x-2] &&maze[y][x-1]<maze[y][x]  && v[y][x-2]==WHITE)dfs(y,x-2);
	if(x <= w-3 && maze[y][x]==maze[y][x+2] &&maze[y][x+1]<maze[y][x]  && v[y][x+2]==WHITE)dfs(y,x+2);
	if(y >= 2 && maze[y][x]==maze[y-2][x] &&maze[y-1][x]<maze[y][x]  && v[y-2][x]==WHITE)dfs(y-2,x);
	if(y <= h-3 && maze[y][x]==maze[y+2][x] &&maze[y+1][x]<maze[y][x]  && v[y+2][x]==WHITE)dfs(y+2,x);

	//hasigo
	if(x >= 1 && abs(maze[y][x]-maze[y][x-1])<=1  && v[y][x-1]==WHITE)dfs(y,x-1);
	if(x <= w-2 && abs(maze[y][x]-maze[y][x+1])<=1  && v[y][x+1]==WHITE)dfs(y,x+1);
	if(y >= 1 && abs(maze[y][x]-maze[y-1][x])<=1  && v[y-1][x]==WHITE)dfs(y-1,x);
	if(y <= h-2 && abs(maze[y][x]-maze[y+1][x])<=1  && v[y+1][x]==WHITE)dfs(y+1,x);
	
	return ;
}

int main()
{
	cin >> h >> w;
	cin >> sy >> sx >> gy >> gx;
	REP(i,h){
		char str[256];
		scanf("%s",str);
		REP(j,w){
			maze[i][j] = str[j]-'0';
			v[i][j] = WHITE;
		}
	}

	dfs(sy-1,sx-1);

	// REP(i,h){
	// 	REP(j,w){
	// 		if(i==sy-1 && j == sx-1)
	// 			cout << "S";
	// 		else cout << maze[i][j];
	// 	}cout<<endl;
	// }
	// cout << maze[sy-1][sx-1] << endl;

	// REP(i,h){
	// 	REP(j,w){
	// 		if(i==gy-1 && j == gx-1)
	// 			cout << "G" ;
	// 		else cout << v[i][j];
	// 	}cout<<endl;
	// }
	// cout << endl << gx << gy << endl;
	if(v[gy-1][gx-1]==BLACK)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}














0