結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
Lay_ec
|
| 提出日時 | 2016-09-22 22:55:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,173 bytes |
| コンパイル時間 | 509 ms |
| コンパイル使用メモリ | 80,348 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-05 07:04:59 |
| 合計ジャッジ時間 | 1,237 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
#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;
}
Lay_ec