結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
rapurasu
|
| 提出日時 | 2016-09-23 15:52:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,476 bytes |
| コンパイル時間 | 1,129 ms |
| コンパイル使用メモリ | 164,204 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-05 07:08:38 |
| 合計ジャッジ時間 | 1,837 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
bool dp[51][51];
int g[51][51];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
REP(i,51){
REP(j,51){
dp[i][j]=false;
}
}
int h,w,sx,sy,gx,gy;
cin>>h>>w>>sx>>sy>>gx>>gy;
REP(i,h){
string s;
cin>>s;
REP(j,w){
g[i+1][j+1]=s[j]-'0';
}
}
queue<pair<int,int> > que;
que.push(make_pair(sx,sy));
dp[sx][sy]=true;
bool check=false;
while(!que.empty()){
pair<int,int> p=que.front();
if(p.first==gx&&p.second==gy){
check=true;
break;
}
que.pop();
REP(i,4){
int x=p.first+dx[i];
int y=p.second+dy[i];
if(x>0&&y>0&&x<=h&&y<=w){
if(dp[x][y]==false&&abs(g[p.first][p.second]-g[x][y])<=1){
dp[x][y]=true;
que.push(make_pair(x,y));
}
}
x+=dx[i];
y+=dy[i];
if(x>0&&y>0&&x<=h&&y<=w){
if(dp[x][y]==false&&g[p.first][p.second]==g[x][y]&&g[x][y]>=g[(x+p.first)/2][(y+p.second)/2]){
dp[x][y]=true;
que.push(make_pair(x,y));
}
}
}
}
if(check==true){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
rapurasu