結果

問題 No.129 お年玉(2)
ユーザー jjjj
提出日時 2016-10-10 18:14:21
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 450 ms / 5,000 ms
コード長 867 bytes
コンパイル時間 2,157 ms
コンパイル使用メモリ 26,680 KB
実行使用メモリ 394,044 KB
最終ジャッジ日時 2023-08-18 17:44:54
合計ジャッジ時間 15,868 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 189 ms
393,380 KB
testcase_01 AC 184 ms
393,212 KB
testcase_02 AC 179 ms
393,176 KB
testcase_03 AC 165 ms
393,244 KB
testcase_04 AC 181 ms
393,176 KB
testcase_05 AC 268 ms
393,628 KB
testcase_06 AC 355 ms
393,892 KB
testcase_07 AC 413 ms
393,932 KB
testcase_08 AC 245 ms
393,680 KB
testcase_09 AC 396 ms
393,996 KB
testcase_10 AC 419 ms
393,992 KB
testcase_11 AC 313 ms
393,804 KB
testcase_12 AC 224 ms
393,792 KB
testcase_13 AC 209 ms
393,756 KB
testcase_14 AC 366 ms
393,964 KB
testcase_15 AC 330 ms
393,888 KB
testcase_16 AC 329 ms
393,940 KB
testcase_17 AC 386 ms
393,880 KB
testcase_18 AC 386 ms
393,900 KB
testcase_19 AC 300 ms
393,904 KB
testcase_20 AC 377 ms
394,040 KB
testcase_21 AC 442 ms
393,964 KB
testcase_22 AC 333 ms
393,812 KB
testcase_23 AC 424 ms
393,936 KB
testcase_24 AC 245 ms
393,848 KB
testcase_25 AC 302 ms
393,844 KB
testcase_26 AC 308 ms
393,828 KB
testcase_27 AC 312 ms
393,832 KB
testcase_28 AC 450 ms
394,044 KB
testcase_29 AC 165 ms
393,260 KB
testcase_30 AC 162 ms
393,260 KB
testcase_31 AC 161 ms
393,260 KB
testcase_32 AC 162 ms
393,224 KB
testcase_33 AC 162 ms
393,264 KB
testcase_34 AC 162 ms
393,244 KB
testcase_35 AC 164 ms
393,248 KB
testcase_36 AC 165 ms
393,272 KB
testcase_37 AC 165 ms
393,272 KB
testcase_38 AC 199 ms
393,488 KB
testcase_39 AC 217 ms
393,500 KB
testcase_40 AC 305 ms
393,732 KB
testcase_41 AC 270 ms
393,632 KB
testcase_42 AC 207 ms
393,464 KB
testcase_43 AC 193 ms
393,476 KB
testcase_44 AC 356 ms
393,872 KB
testcase_45 AC 187 ms
393,436 KB
testcase_46 AC 195 ms
393,504 KB
testcase_47 AC 438 ms
393,936 KB
testcase_48 AC 259 ms
393,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

program main
  implicit none
  integer*8::N,M,amari
  integer*4,parameter::sen=1000
  integer*4::memo(10**4,0:10**4)
  data memo/100010000*0/

  read *,N,M
  N = N/sen
  amari = MOD(N, M)
  memo = 0
  print '(i0)', get_combination(M, MIN(amari, M-amari), memo)
contains
  recursive function get_combination(N,R, memo) result(NCR)
    integer*8::N,R,NCR
    integer*4,parameter::modular=10**9
    integer*4::memo(10**4,0:10**4)
    if(memo(N,R).ne.0) then
       NCR = memo(N,R)
    else
       if(R.eq.0) then
          NCR = 1
       else if(R.eq.1) then
          NCR = N
       else if(N-R.lt.R) then
          NCR = get_combination(N, N-R, memo)
       else
          NCR = get_combination(N-1,R,memo) + get_combination(N-1,R-1,memo)
       end if
       NCR = MOD(NCR, modular)
       memo(N,R) = NCR
    end if
   end function get_combination
 end program main
0