結果

問題 No.424 立体迷路
ユーザー akakimidori
提出日時 2017-06-21 02:55:52
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 978 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 21,760 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 07:14:16
合計ジャッジ時間 761 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
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-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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0