結果

問題 No.3 ビットすごろく
ユーザー 37zigen37zigen
提出日時 2018-04-02 09:20:26
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,865 bytes
コンパイル時間 1,041 ms
コンパイル使用メモリ 29,228 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 00:58:35
合計ジャッジ時間 2,134 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.f90:73:33:

         integer function bitcount(n)
                                 1
Warning: Interface mismatch in global procedure ‘bitcount’ at (1): INTENT mismatch in argument 'n' [-Wargument-mismatch]

ソースコード

diff #

module que_module
    implicit none

    type que
        private
        integer::s=1,t=1
        integer,allocatable::contents(:)
    contains
        procedure::is_empty
        procedure::poll
        procedure::peek
        procedure::put
    end type que

    interface que
        module procedure init
    end interface

contains

    type(que) function init(n)
        integer::n
        allocate(init%contents(n))
    end function init

    logical function is_empty(q)
        class(que)::q
        logical::ret
        ret=((q%s).eq.(q%t))
        is_empty=ret
    end function is_empty

    integer function poll(q)
        class(que)::q
        poll=q%contents(q%s)
        q%s=q%s+1
    end function poll

    integer function peek(q)
        class(que)::q
        peek=q%contents(q%s)
    end function peek

    subroutine put(q,v)
        class(que)::q
        integer::v
        q%contents(q%t)=v
        q%t=q%t+1
    end subroutine put

end module que_module

integer function bitcount(n)
    implicit none
    integer,intent(in)::n
    integer::n_
    bitcount=0

    n_=n
    do while(n_>0)
        if(mod(n_,2)==1)bitcount=bitcount+1
        n_=n_/2
    end do

end function bitcount


program main
    use que_module
    implicit none

    interface
        integer function bitcount(n)
            integer::n
        end function bitcount
    end interface

    integer::i,j,k,l,m,n,dx,inf=30000
    integer::a(10000)
    type(que)::q

    q=que(40000)
    read*,n
    do i=1,size(a)
        a(i)=inf
    end do
    a(1)=1

    call q%put(1)

    do while(.not.q%is_empty())
        i=q%poll()
        dx=bitcount(i)
        do j=i-dx,i+dx,2*dx
            if(j<0.or.j>n)cycle
            if(a(j)/=inf)cycle
            a(j)=a(i)+1
            call q%put(j)
        end do
    end do

    if(a(n)==inf)a(n)=-1
    print*,a(n)

end program

0