結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2016-09-22 22:42:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,044 bytes |
コンパイル時間 | 1,617 ms |
コンパイル使用メモリ | 176,572 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-05 07:01:09 |
合計ジャッジ時間 | 2,052 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using namespace std; // #define int long long using ll=long long; using vi=vector<int>; using vl=vector<long long>; using pii=pair<int,int>; #define ITR(v,c) for(auto v=begin(c);v!=end(c);v++) #define FOR(v,a,n) for(int v=a;v<(int)(n);v++) #define FORE(x,arr) for(auto &x:arr) #define REP(v,n) FOR(v,0,n) #define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--) #define ALL(c) begin(c),end(c) #define RALL(c) rbegin(c),rend(c) #define DUMP(x) cerr<<#x<<":="<<(x)<<endl const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0}; const int DX9[9]={0,1,1,1,0,-1,-1,-1,0}, DY9[9]={-1,-1,0,1,1,1,0,-1,0}; const int INF=1e9; const long long INFLL=1e18; template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){ os<<"("<<p.first<<" "<<p.second<<")";return os;} template<class T>ostream&operator<<(ostream &os,const vector<T> &v){ ITR(i,v)os<<*i<<(i==end(v)-1?"":" ");return os;} //------------------------------------------------------------------------------ bool r[51][51]; signed main() { int h,w; pii s,g; cin>>h>>w; cin>>s.first>>s.second; s.first--; s.second--; cin>>g.first>>g.second; g.first--; g.second--; vector<string> b(h); REP(i,h) cin>>b[i]; queue<pii> q; r[s.first][s.second]=true; q.push(s); while(!q.empty()) { pii p=q.front(); q.pop(); if(p==g) { cout<<"YES"<<endl; return 0; } REP(i,4) { int nx=p.second+DX[i], ny=p.first+DY[i]; if(ny<0 || ny>=h || nx<0 || nx>=w) continue; if(!r[ny][nx] && abs(b[ny][nx]-b[p.first][p.second])<=1) { r[ny][nx]=true; q.push(pii(ny,nx)); } nx+=DX[i]; ny+=DY[i]; if(ny<0 || ny>=h || nx<0 || nx>=w) continue; if(!r[ny][nx] && b[ny][nx]==b[p.first][p.second] && b[ny-DY[i]][nx-DX[i]]<b[p.first][p.second]) { r[ny][nx]=true; q.push(pii(ny,nx)); } } } cout<<"NO"<<endl; return 0; }