結果

問題 No.673 カブトムシ
ユーザー 37zigen37zigen
提出日時 2018-04-14 00:07:36
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,690 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 30,348 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-12 18:12:41
合計ジャッジ時間 1,333 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.f90:9:25:

         h=size(a)/size(a(0,:))
                         1
Warning: Array reference at (1) is out of bounds (0 < 1) in dimension 1
Main.f90:10:17:

         w=size(b(0,:))
                 1
Warning: Array reference at (1) is out of bounds (0 < 1) in dimension 1
Main.f90:11:25:

         m=size(b)/size(b(0,:))
                         1
Warning: Array reference at (1) is out of bounds (0 < 1) in dimension 1

ソースコード

diff #

module md
contains

    function mul(a,b,mo)
        implicit none
        integer::i,j,k,h,w,m
        integer(kind=8),intent(in)::a(:,:),b(:,:),mo
        integer(kind=8),allocatable::mul(:,:)
        h=size(a)/size(a(0,:))
        w=size(b(0,:))
        m=size(b)/size(b(0,:))
        allocate(mul(h,w))
        do i=1,h
            do j=1,w
                mul(i,j)=0
            end do
        end do
        do i=1,h
            do j=1,w
                do k=1,m
                    mul(i,j)=mul(i,j)+mod(a(i,k)*b(k,j),mo)
                    mul(i,j)=mod(mul(i,j),mo)
                end do
            end do
        end do
    end function


    function pow(a,n,mo)
        integer(kind=8),value::n,mo
        integer(kind=8)::a(:,:)
        integer(kind=8)::pow(2,2)
        do i=1,2
            do j=1,2
                if(i==j)then
                    pow(i,j)=1
                else
                    pow(i,j)=0
                end if
            end do
        end do
        do while(n>0)
            if(mod(n,2)==1)pow=mul(pow,a,mo)
            n=n/2
            a=mul(a,a,mo)
        end do
    end function

    function inv(a,mo)
        integer(kind=8)::mo
        integer(kind=8)::a(:,:)
        integer(kind=8),allocatable::inv(:,:)
        inv=pow(a,mo-2,mo)
    end function

end module



program main
    use md
    implicit none
    integer(kind=8)::b,c,d
    integer(kind=8)::ans,mat(2,2),vec(2,1)
    integer(kind=8),parameter::mo=1000000007
    read*,b,c,d
    b=mod(b,mo)
    c=mod(c,mo)
    vec(1,1)=0
    vec(2,1)=b
    mat(1,1)=c
    mat(1,2)=c
    mat(2,1)=0
    mat(2,2)=1
    mat=pow(mat,d,mo)
    vec=mul(mat,vec,mo)
    print*,vec(1,1)
end program
0