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 ! 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 .ne. 0) then print '(i0)',max_cdist exit end if end do end program