結果

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

テストケース

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

ソースコード

diff #

  integer(kind=4)::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

  if(H.eq.1.and.W.eq.1) then
     print '(a)',"1"
     return
  endif

  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


  ! 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 .and. rcdist(i,j).eq.0) then
              goto 100
           end if
        end do
     end do

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

     100 continue
  end do
end program
0