結果

問題 No.424 立体迷路
ユーザー sggkshiosggkshio
提出日時 2016-12-06 01:05:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,552 bytes
コンパイル時間 806 ms
コンパイル使用メモリ 85,640 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 16:59:38
合計ジャッジ時間 1,975 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>



using namespace std;

int gcd(int x,int y){
	return y?gcd(y,x%y):x;
}
bool f[55][55];

int main(){
	
	int h,w,a,b,c,d;
	cin>>h>>w>>a>>b>>c>>d;
	a--,b--,c--,d--;
	vector<string>p(h);

	for(int i=0;i<h;i++)
		cin>>p[i];

	queue<int>x,y;
	x.push(a),y.push(b);

	while(x.size()){
		int t=x.front(),r=y.front();
		//cout<<t<<r<<endl;;
		if(t==c&&r==d){
			cout<<"YES"<<endl;
			return 0;
		}
		
		if(t<h-1){if(abs(p[t][r]-p[t+1][r])<2&&t<h-1&&!f[t+1][r])f[t+1][r]=1,x.push(t+1),y.push(r);}
		
		if(t){if(abs(p[t][r]-p[t-1][r])<2&&t>0&&!f[t-1][r])f[t-1][r]=1,x.push(t-1),y.push(r);}
		if(r<w-1){if(abs(p[t][r]-p[t][r+1])<2&&r<w-1&&!f[t][r+1])f[t][r+1]=1,x.push(t),y.push(r+1);}
		if(r){if(abs(p[t][r]-p[t][r-1])<2&&r>0&&!f[t][r-1])f[t][r-1]=1,x.push(t),y.push(r-1);}
		
		if(t<h-2){if(p[t][r]>p[t+1][r]&&abs(p[t][r]-p[t+2][r])<1&&t<h-2&&!f[t+2][r])f[t+2][r]=1,x.push(t+2),y.push(r);}
		if(t>1){if(p[t][r]>p[t-1][r]&&abs(p[t][r]-p[t-2][r])<1&&t>1&&!f[t-2][r])f[t-2][r]=1,x.push(t-2),y.push(r);}
		if(r<w-2){if(p[t][r]>p[t][r+1]&&abs(p[t][r]-p[t][r+2])<1&&r<w-2&&!f[t][r+2])f[t][r+2]=1,x.push(t),y.push(r+2);}
		if(r>1){if(p[t][r]>p[t][r-1]&&abs(p[t][r]-p[t][r-2])<1&&r>1&&!f[t][r-2])f[t][r-2]=1,x.push(t),y.push(r-2);}
		x.pop(),y.pop();


	}
	cout<<"NO"<<endl;

	return 0;
	

}


	
0