結果

問題 No.424 立体迷路
ユーザー akakimidoriakakimidori
提出日時 2017-06-21 02:54:59
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 968 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 21,888 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 06:29:00
合計ジャッジ時間 1,210 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 0 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 0 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 0 ms
6,944 KB
testcase_06 AC 0 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 0 ms
6,940 KB
testcase_09 AC 0 ms
6,944 KB
testcase_10 AC 1 ms
6,940 KB
testcase_11 AC 0 ms
6,940 KB
testcase_12 WA -
testcase_13 AC 1 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 1 ms
6,944 KB
testcase_19 WA -
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 WA -
testcase_23 AC 1 ms
6,944 KB
testcase_24 WA -
testcase_25 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:27:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |   scanf("%d%d",&h,&w);
      |   ^~~~~~~~~~~~~~~~~~~
main.c:29:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |   scanf("%d%d%d%d",&sx,&sy,&gx,&gy);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:35:7: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |       scanf("%1d",board+i*w+j);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

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,sy,board,h,w,flag);
  printf("%s\n",flag[gx*w+gy]?"YES":"NO");
  return;
}

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