結果

問題 No.424 立体迷路
ユーザー Lay_ecLay_ec
提出日時 2016-09-22 22:55:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,173 bytes
コンパイル時間 543 ms
コンパイル使用メモリ 75,868 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 16:48:39
合計ジャッジ時間 1,614 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>

using namespace std;

int h,w;
int sx,sy,gx,gy;
int cell[100][100];
bool vis[100][100];

int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
bool dfs(int x,int y){


	if(x==gx && y==gy) return true;

	for(int i=0;i<4;i++){
		int nx=x+dx[i],ny=y+dy[i];
		if(0<=nx && nx<h && 0<=ny && ny<w && abs(cell[nx][ny]-cell[x][y])<=1 && !vis[nx][ny]){
			vis[nx][ny]=true;
			if(dfs(nx,ny)) return true;
		}
	}

	for(int i=0;i<4;i++){
		int nx=x+2*dx[i],ny=y+2*dy[i];

		if(0<=nx && nx<h && 0<=ny && ny<w && cell[nx][ny]==cell[x][y] && cell[nx][ny]>cell[x+dx[i]][y+dy[i]] && !vis[nx][ny]){
			vis[nx][ny]=true;
			if(dfs(nx,ny)) return true;
		}
	}

	return false;
}

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

	sx--,sy--,gx--,gy--;
	vis[sx][sy]=true;

	for(int i=0;i<h;i++){
		string s;
		cin>>s;

		for(int j=0;j<w;j++) cell[i][j]=s[j]-'0';
	}

	if(dfs(sx,sy)) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
    
    return 0;
}
0