結果

問題 No.424 立体迷路
ユーザー vjudge1
提出日時 2025-07-27 13:46:49
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 968 bytes
コンパイル時間 1,625 ms
コンパイル使用メモリ 162,244 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-07-27 13:46:53
合計ジャッジ時間 3,211 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
int n,m,sx,sy,zx,zy,a[57][57];
bool vis[57][57];
queue<pair<int,int>>q;
signed main(){

	cin>>n>>m>>sx>>sy>>zx>>zy;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++){
		char ch;cin>>ch;
		a[i][j]=ch-'0';
	}
	q.push({sx,sy});
	vis[sx][sy]=1;
	while(!q.empty()){
		int x=q.front().first;
		int y=q.front().second;
		if(x==zx&&y==zy){
			puts("YES");
			return 0;
		}q.pop();
		for(int i=0;i<4;i++){
		int tx=x+dx[i];
			int ty=y+dy[i];
			if(tx>=1 && tx<=n && ty>=1 && ty<=m && !vis[tx][ty]){
				if(a[tx][ty]==a[x][y] || abs(a[tx][ty]-a[x][y])==1){
					q.push({tx,ty});
					vis[tx][ty]=1;
				}
			}
			int tx2=tx+dx[i];
			int ty2=ty+dy[i];
			if(tx2>=1 && tx2<=n && ty2>=1 && ty2<=m && !vis[tx2][ty2]){
				if(a[tx2][ty2]==a[x][y] && a[tx][ty]<a[x][y]){
					q.push({tx2,ty2});
					vis[tx2][ty2]=1;
				}
			}
		}
	}
	puts("NO");
}
0