integer(kind=4)::H,W logical,allocatable::map(:,:) logical,parameter::riku=.true.,umi=.false. integer,allocatable::rcdist(:,:) character*3000::string integer::i,j,k,max_cdist read *,H,W allocate(map(0:W+1,0:H+1)) allocate(rcdist(1:W,1:H)) do i=1,H read *, string do j=1,W if(string(j:j)=='.') then map(j,i)=umi else map(j,i)=riku end if end do end do map(0, 0:H+1) =umi map(W+1, 0:H+1) =umi map(0:W+1, 0) =umi map(0:W+1, H+1) =umi rcdist(1:W,1:H)=0 do i=1,W do j=1,H if (map(i,j).eqv.umi) then continue end if do k=1,MIN(MIN(W+1-i,i),MIN(H+1-j,j)) if (ANY(map(i+k,j-k:j+k).eqv.umi)) then rcdist(i,j)=k exit else if(ANY(map(i-k,j-k:j+k).eqv.umi)) then rcdist(i,j)=k exit else if(ANY(map(i-k+1:i+k-1,j+k).eqv.umi)) then rcdist(i,j)=k exit else if(ANY(map(i-k+1:i+k-1,j-k).eqv.umi)) then rcdist(i,j)=k exit end if end do end do end do max_cdist=0 do i=1,W do j=1,H if(map(i,j).eqv.riku) then max_cdist=MAX(max_cdist, rcdist(i,j)) end if end do end do print '(i0)',max_cdist end program