結果
問題 | No.424 立体迷路 |
ユーザー |
![]() |
提出日時 | 2019-04-18 12:48:45 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,301 bytes |
コンパイル時間 | 2,264 ms |
コンパイル使用メモリ | 203,040 KB |
最終ジャッジ日時 | 2025-01-07 02:21:28 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 21 |
ソースコード
#include<bits/stdc++.h>using namespace std;using Int = long long;template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}//INSERT ABOVE HEREint dp[55][55];signed main(){int h,w;cin>>h>>w;int sy,sx,gy,gx;cin>>sy>>sx>>gy>>gx;sy--;sx--;gy--;gx--;vector<string> st(h);for(int i=0;i<h;i++) cin>>st[i];memset(dp,0,sizeof(dp));using P = pair<int, int>;queue<P> qu;dp[sy][sx]=1;qu.emplace(sy,sx);int dy[]={0,0,1,-1};int dx[]={1,-1,0,0};auto in=[&](int y,int x){return 0<=y&&y<h&&0<=x&&x<w;};while(!qu.empty()){int y,x;tie(y,x)=qu.front();qu.pop();//cout<<y<<" "<<x<<":"<<st[y][x]<<endl;for(int k=0;k<4;k++){int ny=y+dy[k],nx=x+dx[k];if(!in(ny,nx)||dp[ny][nx]) continue;if(abs(st[y][x]-st[ny][nx])>1) continue;dp[ny][nx]=1;qu.emplace(ny,nx);}for(int k=0;k<4;k++){int ny=y+dy[k]*2,nx=x+dx[k]*2;int iy=y+dy[k],ix=x+dx[k];if(!in(ny,nx)||dp[ny][nx]) continue;if(st[y][x]!=st[ny][nx]) continue;if(st[y][x]<=st[iy][ix]) continue;dp[ny][nx]=1;qu.emplace(ny,nx);}}cout<<(dp[gy][gx]?"YES":"NO")<<endl;return 0;}