結果
| 問題 | No.13 囲みたい! | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-04-02 17:45:24 | 
| 言語 | Fortran (gFortran 14.2.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 1,230 bytes | 
| コンパイル時間 | 1,182 ms | 
| コンパイル使用メモリ | 33,408 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-26 06:41:19 | 
| 合計ジャッジ時間 | 1,925 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 | 
ソースコード
module mod
    implicit none
    integer::m(100,100)
    integer::h,w
    logical::vis(100,100)
contains
    recursive logical function dfs(curh,curw,preh,prew)result(ret)
        integer,intent(in)::curh,curw,preh,prew
        integer::dh(4)=[1,-1,0,0],dw(4)=[0,0,1,-1]
        integer::i,j,k,l,x,y,z
        ret=.false.
        vis(curh,curw)=.true.
        do i=1,4
            y=curh+dh(i)
            x=curw+dw(i)
            if(.not.(1<=x.and.x<=w.and.1<=y.and.y<=h))cycle
            if(y==preh.and.x==prew)cycle
            if(m(curh,curw)/=m(y,x))cycle
            if(vis(y,x))then
                ret=.true.
            else
                ret=ret.or.dfs(y,x,curh,curw)
            end if
        end do
    end function
end module
program main
    use mod
    implicit none
    integer::i,j,k,l,n,x,y,z
    logical::ans=.false.
    read(*,*)w,h
    do i=1,h
        read(*,*)(m(i,j),j=1,w)
    end do
    do i=1,h
        do j=1,w
            vis(i,j)=.false.
        end do
    end do
    do i=1,h
        do j=1,w
            if(vis(i,j))cycle
            ans=ans.or.dfs(i,j,-1,-1)
        end do
    end do
    if(ans)then
        print*,"possible"
    else
        print*,"impossible"
    end if
end program
            
            
            
        