結果
問題 | No.424 立体迷路 |
ユーザー | HO_RI1991 |
提出日時 | 2016-09-22 23:03:01 |
言語 | C++11 (gcc 11.4.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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 1 ms
5,376 KB |
testcase_09 | AC | 1 ms
5,376 KB |
testcase_10 | AC | 1 ms
5,376 KB |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 1 ms
5,376 KB |
testcase_15 | AC | 1 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | AC | 1 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 1 ms
5,376 KB |
testcase_22 | AC | 1 ms
5,376 KB |
testcase_23 | AC | 1 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 1 ms
5,376 KB |
ソースコード
#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; }