結果

問題 No.424 立体迷路
ユーザー jjjj
提出日時 2016-09-22 22:56:57
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,438 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 31,104 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 16:48:49
合計ジャッジ時間 1,294 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

program main
  implicit none
  integer::h,w,sx,sy,gx,gy
  character*50::input
  integer,allocatable::height(:,:)
  integer,allocatable::reach(:,:)
  integer::i,j,itr,nexti,nextj
  read *, h,w
  read *, sx,sy,gx,gy
  allocate(height(-1:h+2,-1:w+2),reach(h,w))

  do i=1,h
     read *,input
     do j=1,LEN_TRIM(input)
        height(i,j) = ICHAR(input(j:j))-ICHAR('0')
     end do
  end do
  height(-1:0   ,:)       = 100
  height(h+1:h+2,:)       = 100
  height(:      ,-1:0)    = 100
  height(:      ,w+1:w+2) = 100

  reach = 0
  reach(sx,sy) = 1

  do itr=1,h*w
     do i=1,h
        do j=1,w
           if(reach(i,j).ne.1) cycle
           if(abs(height(i,j)-height(i,j+1)).le.1) reach(i,j+1) = 1
           if(abs(height(i,j)-height(i,j-1)).le.1) reach(i,j-1) = 1
           if(abs(height(i,j)-height(i+1,j)).le.1) reach(i+1,j) = 1
           if(abs(height(i,j)-height(i-1,j)).le.1) reach(i-1,j) = 1
           if(height(i,j).eq.height(i,j+2).and.height(i,j).gt.height(i,j+1)) reach(i,j+2) = 1
           if(height(i,j).eq.height(i,j-2).and.height(i,j).gt.height(i,j-1)) reach(i,j-2) = 1
           if(height(i,j).eq.height(i+2,j).and.height(i,j).gt.height(i+1,j)) reach(i+2,j) = 1
           if(height(i,j).eq.height(i-2,j).and.height(i,j).gt.height(i-1,j)) reach(i-2,j) = 1
        end do
     end do
     if(reach(gx,gy).eq.1) then
        print '(a)',"YES"
        return
     end if
  end do
  print '(a)',"NO"
end program main
0