結果
| 問題 | 
                            No.424 立体迷路
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-12-06 00:57:15 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,472 bytes | 
| コンパイル時間 | 817 ms | 
| コンパイル使用メモリ | 88,952 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-27 22:28:09 | 
| 合計ジャッジ時間 | 1,597 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 19 WA * 2 | 
ソースコード
#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<<p[t][r];
		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(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(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(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(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;
	
}