結果

問題 No.424 立体迷路
ユーザー shop_oneshop_one
提出日時 2019-08-06 17:59:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 764 bytes
コンパイル時間 2,827 ms
コンパイル使用メモリ 66,076 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-25 18:01:53
合計ジャッジ時間 1,843 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
using namespace std;
int h,w;
bool can[51][51];
string b[51];
void search(int x,int y){
  int dx[]={1,0,-1,0},dy[]={0,1,0,-1},nx,ny,nnx,nny;
  if(can[x][y])return;
  can[x][y]=true;
  for(int i=0;i<4;i++){
    nx=x+dx[i];
    ny=y+dy[i];
    if(nx<0||nx>=h||ny<0||ny>=w) continue;
    if(abs(b[x][y]-b[nx][ny])<=1) search(nx,ny);

    nnx=x+2*dx[i];
    nny=y+2*dy[i];
    if(nnx<0||nnx>=h||nny<0||nny>=w) continue;
    if(b[x][y]==b[nnx][nny]){
      if(b[x][y]-b[nx][ny]>=0) search(nnx,nny);
    }
  }
}
int main(){
  int sx,sy,gx,gy;
  cin >> h >> w>>sx>>sy>>gx>>gy;
  for(int i=0;i<h;i++){
    cin >> b[i];
    fill(can[i],can[i]+w,false);
  }
  sx--;sy--;gx--;gy--;
  search(sx,sy);
  if(can[gx][gy])cout <<"YES\n";
  else cout <<"NO\n";
}
0