結果
| 問題 |
No.424 立体迷路
|
| コンテスト | |
| ユーザー |
HO_RI1991
|
| 提出日時 | 2016-09-22 23:03:01 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 3,341 bytes |
| コンパイル時間 | 815 ms |
| コンパイル使用メモリ | 106,856 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 07:05:52 |
| 合計ジャッジ時間 | 1,511 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 21 |
ソースコード
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<algorithm>
#include<list>
#include<cmath>
#include<iomanip>
#include<queue>
#include<functional>
#include<climits>
#include<iterator>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include<set>
#include<typeinfo>
using namespace std;
const double pi=4*atan(1.0);
constexpr long long mod=static_cast<long long>(1e9+7);
using cWeightEdges=vector<vector<pair<int,int>>>;
using cEdges=vector<vector<int>>;
int main() {
int h,w;
cin>>h>>w;
int Sx,Sy,Gx,Gy;
cin>>Sx>>Sy>>Gx>>Gy;
--Sx,--Sy,--Gx,--Gy;
vector<vector<int>> Height(h,vector<int>(w,0));
for(auto& val:Height){
string str;
cin>>str;
for(int i=0;i<w;++i){
val[i]=str[i]-'0';
}
}
vector<vector<bool>> memo(h,vector<bool>(w,0));
queue<pair<int,int>> Q;
Q.push(make_pair(Sx,Sy));
memo[Sx][Sy]=true;
bool IsFind=false;
while(!Q.empty()){
auto now=Q.front();
Q.pop();
if(now.first==Gx && now.second==Gy){
IsFind=true;
break;
}
if(now.first+1<h && Height[now.first][now.second]-1<=Height[now.first+1][now.second] && Height[now.first+1][now.second]<=Height[now.first][now.second]+1 && !memo[now.first+1][now.second]){
memo[now.first+1][now.second]=true;
Q.push(make_pair(now.first+1,now.second));
}
if(0<=now.first-1 && Height[now.first][now.second]-1<=Height[now.first-1][now.second] && Height[now.first-1][now.second]<=Height[now.first][now.second]+1 && !memo[now.first-1][now.second]){
memo[now.first-1][now.second]=true;
Q.push(make_pair(now.first-1,now.second));
}
if(now.second+1<w && Height[now.first][now.second]-1<=Height[now.first][now.second+1] && Height[now.first][now.second+1]<=Height[now.first][now.second]+1 && !memo[now.first][now.second+1]){
memo[now.first][now.second+1]=true;
Q.push(make_pair(now.first,now.second+1));
}
if(0<=now.second-1 && Height[now.first][now.second]-1<=Height[now.first][now.second-1] && Height[now.first][now.second-1]<=Height[now.first][now.second]+1 && !memo[now.first][now.second-1]){
memo[now.first][now.second-1]=true;
Q.push(make_pair(now.first,now.second-1));
}
if(now.first+2<h && Height[now.first][now.second]==Height[now.first+2][now.second] && Height[now.first+1][now.second]<Height[now.first][now.second] && !memo[now.first+2][now.second]){
memo[now.first+2][now.second]=true;
Q.push(make_pair(now.first+2,now.second));
}
if(0<=now.first-2 && Height[now.first][now.second]==Height[now.first-2][now.second] && Height[now.first-1][now.second]<Height[now.first][now.second] && !memo[now.first-2][now.second]){
memo[now.first-2][now.second]=true;
Q.push(make_pair(now.first-2,now.second));
}
if(now.second+2<w && Height[now.first][now.second]==Height[now.first][now.second+2] && Height[now.first][now.second+1]<Height[now.first][now.second] && !memo[now.first][now.second+2]){
memo[now.first][now.second+2]=true;
Q.push(make_pair(now.first,now.second+2));
}
if(0<=now.second-2 && Height[now.first][now.second]==Height[now.first][now.second-2] && Height[now.first][now.second-1]<Height[now.first][now.second] && !memo[now.first][now.second-2]){
memo[now.first][now.second-2]=true;
Q.push(make_pair(now.first,now.second-2));
}
}
if(IsFind)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
//system("pause");
return 0;
}
HO_RI1991