結果

問題 No.424 立体迷路
ユーザー akakimidoriakakimidori
提出日時 2017-06-21 02:55:52
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 978 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 25,440 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-18 17:01:11
合計ジャッジ時間 1,458 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>

#define ABS(a) ((a)>0?(a):-(a))

void dfs(int x,int y,int *board,int h,int w,int *flag){
  if(flag[x*w+y]) return;
  flag[x*w+y]=1;

  int d[]={1,0,-1,0,1};
  int i;
  for(i=0;i<4;i++){
    int nx=x+d[i];
    int ny=y+d[i+1];
    if(!(nx>=0 && nx<h && ny>=0 && ny<w)) continue;
    if(ABS(board[x*w+y]-board[nx*w+ny])<=1) dfs(nx,ny,board,h,w,flag);

    int nnx=x+2*d[i];
    int nny=y+2*d[i+1];
    if(!(nnx>=0 && nnx<h && nny>=0 && nny<w)) continue;
    if(board[nnx*w+nny]==board[x*w+y]&&board[nx*w+ny]<board[x*w+y]) dfs(nnx,nny,board,h,w,flag);
  }
  return;
}

void run(void){
  int h,w;
  scanf("%d%d",&h,&w);
  int sx,sy,gx,gy;
  scanf("%d%d%d%d",&sx,&sy,&gx,&gy);
  int board[2500];
  int flag[2500];
  int i,j;
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      scanf("%1d",board+i*w+j);
      flag[i*w+j]=0;
    }
  }
  dfs(sx-1,sy-1,board,h,w,flag);
  printf("%s\n",flag[(gx-1)*w+gy-1]?"YES":"NO");
  return;
}

int main(void){
  run();
  return 0;
}
0