結果

問題 No.157 2つの空洞
ユーザー jjjj
提出日時 2016-08-11 17:41:45
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,933 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 34,852 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 01:28:11
合計ジャッジ時間 1,031 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 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 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

recursive subroutine sub(kuudou,j,i)
  implicit none
  integer::j,i
  integer,allocatable::kuudou(:,:)

  if (kuudou(j+1,i  ).eq.1) then
     kuudou(j+1,i) = 2
     call sub(kuudou,j+1,i)
  end if
  if (kuudou(j-1,i  ).eq.1) then
     kuudou(j-1,i) = 2
     call sub(kuudou,j-1,i)
  end if
  if (kuudou(j  ,i+1).eq.1) then
     kuudou(j,i+1) = 2
     call sub(kuudou,j,i+1)
  end if
  if (kuudou(j  ,i-1).eq.1) then
     kuudou(j,i-1) = 2
     call sub(kuudou,j,i-1)
  end if
end subroutine sub

program main
  implicit none
  interface
     recursive subroutine sub(kuudou,j,i)
       integer::j,i
       integer,allocatable::kuudou(:,:)
     end subroutine sub
  end interface
  integer::W,H,i,j,k
  character*20,allocatable::C(:)
  integer,allocatable::kuudou(:,:)
  read *,W,H

  allocate(C(H))
  allocate(kuudou(0:W+1,0:H+1))
  read *, C

  kuudou = 0
  do i=1,H
     do j=1,W
        if(C(i)(j:j).eq.'.') then
           kuudou(j,i) = 1
        end if
     end do
  end do

  do i=1,H
     do j=1,W
        if(kuudou(j,i).eq.1) then
           kuudou(j,i)=2
           call sub(kuudou,j,i)
           goto 100
        end if
     end do
  end do
100 continue

  do k=2,H+W
     do i=1,H
        do j=1,W
           if(kuudou(j,i).ne.k) cycle
           if ((kuudou(j+1,i  ).eq.1) .or. &
                (kuudou(j-1,i  ).eq.1) .or. &
                (kuudou(j  ,i+1).eq.1) .or. &
                (kuudou(j  ,i-1).eq.1)) then
              print '(i0)' , k-2
              return
           end if
           if (kuudou(j+1,i  ).eq.0) then
              kuudou(j+1,i  ) = k+1
           end if
           if (kuudou(j-1,i  ).eq.0) then
              kuudou(j-1,i  ) = k+1
           end if
           if (kuudou(j,i+1  ).eq.0) then
              kuudou(j,i+1  ) = k+1
           end if
           if (kuudou(j,i-1  ).eq.0) then
              kuudou(j,i-1  ) = k+1
           end if
        end do
     end do
  end do
end program
0