結果

問題 No.402 最も海から遠い場所
ユーザー jjjj
提出日時 2016-07-23 01:12:54
言語 Fortran
(gFortran 13.2.0)
結果
WA  
実行時間 -
コード長 2,246 bytes
コンパイル時間 1,407 ms
コンパイル使用メモリ 37,188 KB
実行使用メモリ 46,208 KB
最終ジャッジ日時 2024-04-24 07:03:14
合計ジャッジ時間 10,349 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 RE -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 RE -
testcase_18 OLE -
testcase_19 OLE -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

  integer(kind=2)::H,W
  character,allocatable::map(:,:)
  character,parameter::riku='#',umi='.'
  integer,allocatable::rcdist(:,:)
  character*3000::string
  integer::cdist,min_cdist,max_cdist

  read *,H,W
  allocate(map(0:W+1,0:H+1))
  allocate(rcdist(0:W+1,0:H+1))

  do i=1,H
     read *, string
     do j=1,W
        map(i,j)=string(j:j)
     end do
  end do

  map(0,:)  =umi
  map(W+1,:)=umi
  map(:,0)  =umi
  map(:,H+1)=umi

  rcdist=0

  do i=0,H+1
     do j=0,W+1
        if (map(i,j).eq.umi) then
           if(map(i+1,j+1).eq.riku) rcdist(i+1,j+1)=1
           if(map(i+1,j-1).eq.riku) rcdist(i+1,j-1)=1
           if(map(i+1,j  ).eq.riku) rcdist(i+1,j  )=1
           if(map(i-1,j+1).eq.riku) rcdist(i-1,j+1)=1
           if(map(i-1,j-1).eq.riku) rcdist(i-1,j-1)=1
           if(map(i-1,j  ).eq.riku) rcdist(i-1,j  )=1
           if(map(i  ,j+1).eq.riku) rcdist(i  ,j+1)=1
           if(map(i  ,j-1).eq.riku) rcdist(i  ,j-1)=1
        end if
     end do
  end do

  print '(8a)',map(1:W,1:H)
  print '(8i2)',rcdist(1:W,1:H)

  ! propagation
  do l=2,MAX(H,W)
     do i=1,W
        do j=1,H
           if (map(i,j).eq.riku .and. rcdist(i,j).eq.l-1) then
              if(map(i+1,j+1).eq.riku .and. rcdist(i+1,j+1).eq.0) rcdist(i+1,j+1)=l
              if(map(i+1,j-1).eq.riku .and. rcdist(i+1,j-1).eq.0) rcdist(i+1,j-1)=l
              if(map(i+1,j  ).eq.riku .and. rcdist(i+1,j  ).eq.0) rcdist(i+1,j  )=l
              if(map(i-1,j+1).eq.riku .and. rcdist(i-1,j+1).eq.0) rcdist(i-1,j+1)=l
              if(map(i-1,j-1).eq.riku .and. rcdist(i-1,j-1).eq.0) rcdist(i-1,j-1)=l
              if(map(i-1,j  ).eq.riku .and. rcdist(i-1,j  ).eq.0) rcdist(i-1,j  )=l
              if(map(i  ,j+1).eq.riku .and. rcdist(i  ,j+1).eq.0) rcdist(i  ,j+1)=l
              if(map(i  ,j-1).eq.riku .and. rcdist(i  ,j-1).eq.0) rcdist(i  ,j-1)=l
           endif
        end do
     end do

     min_cdist=1
     max_cdist=0
     do i=1,W
        do j=1,H
           if(map(i,j).eq.riku) then
              min_cdist = MIN(rcdist(i,j),min_cdist)
              max_cdist = MAX(rcdist(i,j),max_cdist)
           end if
        end do
     end do
     if (min_cdist .eq. 0) then
        print '(i0)',max_cdist
        exit
     end if
  end do
end program
0