結果

問題 No.129 お年玉(2)
ユーザー jjjj
提出日時 2016-10-10 23:04:04
言語 Fortran
(gFortran 14.2.0)
結果
AC  
実行時間 373 ms / 5,000 ms
コード長 867 bytes
コンパイル時間 2,198 ms
コンパイル使用メモリ 32,640 KB
実行使用メモリ 389,584 KB
最終ジャッジ日時 2024-11-28 00:36:04
合計ジャッジ時間 11,058 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

program main
  implicit none
  integer*8::N,M,amari
  integer*8,parameter::sen=1000
  read *,N,M
  N = N/sen
  amari = MOD(N, M)
  amari = MIN(amari, M-amari)
  M = get_combination(M,amari)
contains
  function get_combination(N,R) result(NCR)
    implicit none
    !pascal triangle
    integer*8,intent(in)::N,R
    integer*8::NCR,i,j
    integer*4,allocatable::pascal(:,:)
    integer*4,parameter::modulo=10**9
!    print *, N, R
    if(R.eq.0) then
       NCR = 1
    else if(R.eq.1) then
       NCR = N
    else
       allocate(pascal(0:N, 0:N))
       pascal = 0
       pascal(0,0) =1

       do i=1,N
          do j=0,i
             pascal(j,i) = MOD(pascal(j-1,i-1) + pascal(j,i-1),modulo)
          end do
!          print *,i, pascal(:,i)
       end do
       NCR = pascal(R,N)
    end if
    print '(i0)', NCR
  end function get_combination
end program main
0