結果

問題 No.424 立体迷路
ユーザー jjjj
提出日時 2016-09-22 22:56:57
言語 Fortran
(gFortran 14.2.0)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,438 bytes
コンパイル時間 1,433 ms
コンパイル使用メモリ 36,808 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-05 07:05:05
合計ジャッジ時間 2,131 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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