結果

問題 No.424 立体迷路
ユーザー beetbeet
提出日時 2019-04-18 12:48:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,301 bytes
コンパイル時間 2,234 ms
コンパイル使用メモリ 207,440 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 17:06:41
合計ジャッジ時間 3,233 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 HERE
int 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;
}
0