結果

問題 No.424 立体迷路
ユーザー albicillaalbicilla
提出日時 2016-09-22 23:33:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,562 bytes
コンパイル時間 1,563 ms
コンパイル使用メモリ 166,832 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 16:50:49
合計ジャッジ時間 2,599 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9
#define MAX_h 50
#define MAX_w 50

using ll = long long;

const ll mod = LLONG_MAX;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[4]={2,0,-2,0};
int ddy[4]={0,2,0,-2};
char field[51][51];
bool board[51][51];
int h,w;

void mapo(){
  cout<<endl;
  cout<<"--test--"<<endl;
  REP(i,h){
    REP(j,w){
      if(board[i][j])
      cout<<"1";
      else
      cout<<"0";
    }
    cout<<endl;
  }
}

bool can_ladder(int x,int y,int nx,int ny){
  if(abs((field[x][y]-'0')-(field[nx][ny]-'0'))<=1){
    return true;
  }else{
    return false;
  }
}



bool can_ladder2(int x,int y,int nx,int ny,int nnx,int nny){
  if(abs((field[x][y]-'0')-(field[nnx][nny]-'0'))<1 && (field[x][y]-'0')>(field[nx][ny]-'0')){
    return true;
  }else{
    return false;
  }
}

void dfs(int x,int y){
  board[x][y]=true;
  //mapo();
  REP(i,4){
    int nx=x+dx[i];
    int ny=y+dy[i];
    if(nx>=0&&nx<h&&ny>=0&&ny<w && can_ladder(x,y,nx,ny) && !board[nx][ny]){
      dfs(nx,ny);
    }
    int nnx=x+ddx[i];
    int nny=y+ddy[i];
    if(nnx>=0&&nnx<h&&nny>=0&&nny<w && can_ladder2(x,y,nx,ny,nnx,nny) && !board[nnx][nny]){
      dfs(nnx,nny);
    }
  }
  return;
}
int main(){
  cin>>h>>w;
  int sx,sy,gx,gy;
  cin>>sx>>sy>>gx>>gy;
  sx--;sy--;gx--;gy--;
  REP(i,h){
    REP(j,w){
      cin>>field[i][j];
      board[i][j]=false;
    }
  }
  dfs(sx,sy);
  if(board[gx][gy]==true){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}
0