結果
| 問題 | No.424 立体迷路 |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-07-27 12:39:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 960 bytes |
| コンパイル時間 | 1,657 ms |
| コンパイル使用メモリ | 168,788 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-07-27 12:39:47 |
| 合計ジャッジ時間 | 2,592 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[55][55];
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int sx,sy;
int ex,ey;
bool vis[55][55];
int main(){
cin>>n>>m;
cin>>sx>>sy>>ex>>ey;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
char c;
cin>>c;
a[i][j]=c-'0';
}
}
queue<pair<int,int> > q;
q.push({sx,sy});
while(!q.empty()){
int x=q.front().first;
int y=q.front().second;
if(x==ex && y==ey){
cout<<"YES"<<endl;
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;
}
}
}
}
cout<<"NO"<<endl;
return 0;
}
vjudge1