結果

問題 No.13 囲みたい!
ユーザー 37zigen37zigen
提出日時 2018-04-02 17:45:24
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,230 bytes
コンパイル時間 1,036 ms
コンパイル使用メモリ 27,368 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-08 13:29:52
合計ジャッジ時間 1,970 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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
0